Skip to content

#167410: _initCalled completed twice #9694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/google_sign_in/google_sign_in_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.1

* Fixes Bad state: Future already completed on the web.

## 1.0.0

* **BREAKING CHANGE**: Switches to implementing version 3.0 of the platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,6 @@ void main() {
);
}, throwsAssertionError);
});

testWidgets('must be called for most of the API to work', (_) async {
expect(() async {
await plugin.attemptLightweightAuthentication(
const AttemptLightweightAuthenticationParameters());
}, throwsStateError);

expect(() async {
await plugin.clientAuthorizationTokensForScopes(
const ClientAuthorizationTokensForScopesParameters(
request: AuthorizationRequestDetails(
scopes: <String>[],
userId: null,
email: null,
promptIfUnauthorized: false)));
}, throwsStateError);

expect(() async {
await plugin.signOut(const SignOutParams());
}, throwsStateError);

expect(() async {
await plugin.disconnect(const DisconnectParams());
}, throwsStateError);
});
});

group('support queries', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {

// A future that completes when the JS loader is done.
late Future<void> _jsSdkLoadedFuture;
// A future that completes when the `init` call is done.
Completer<void>? _initCalled;

// A StreamController to communicate status changes from the GisSdkClient.
final StreamController<AuthenticationEvent> _authenticationController;
Expand All @@ -88,27 +86,13 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
return _gisSdkClient!;
}

// This method throws if init or initWithParams hasn't been called at some
// point in the past. It is used by the [initialized] getter to ensure that
// users can't await on a Future that will never resolve.
void _assertIsInitCalled() {
if (_initCalled == null) {
throw StateError(
'GoogleSignInPlugin::init() or GoogleSignInPlugin::initWithParams() '
'must be called before any other method in this plugin.',
);
}
}

/// A future that resolves when the plugin is fully initialized.
///
/// This ensures that the SDK has been loaded, and that the `init` method
/// has finished running.
@visibleForTesting
Future<void> get initialized {
_assertIsInitCalled();
return Future.wait<void>(
<Future<void>>[_jsSdkLoadedFuture, _initCalled!.future]);
return Future.wait<void>(<Future<void>>[_jsSdkLoadedFuture]);
}

/// Stores the client ID if it was set in a meta-tag of the page.
Expand All @@ -132,8 +116,6 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
assert(params.serverClientId == null,
'serverClientId is not supported on Web.');

_initCalled = Completer<void>();

await _jsSdkLoadedFuture;

_gisSdkClient ??= GisSdkClient(
Expand All @@ -143,8 +125,6 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
authenticationController: _authenticationController,
loggingEnabled: kDebugMode,
);

_initCalled!.complete(); // Signal that `init` is fully done.
}

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android, iOS and Web.
repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
version: 1.0.0
version: 1.0.1

environment:
sdk: ^3.6.0
Expand Down