diff --git a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md index 86b1a053fd7..03924506928 100644 --- a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.1 + +* Fixes Bad state: Future already completed on the web. + ## NEXT * Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. diff --git a/packages/google_sign_in/google_sign_in_web/example/integration_test/google_sign_in_web_test.dart b/packages/google_sign_in/google_sign_in_web/example/integration_test/google_sign_in_web_test.dart index 57fdaa78986..0f6b9b63762 100644 --- a/packages/google_sign_in/google_sign_in_web/example/integration_test/google_sign_in_web_test.dart +++ b/packages/google_sign_in/google_sign_in_web/example/integration_test/google_sign_in_web_test.dart @@ -90,35 +90,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: [], - 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', () { diff --git a/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart b/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart index 3142536fb5e..bf75c0505d6 100644 --- a/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart +++ b/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart @@ -49,10 +49,9 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { @visibleForTesting GisSdkClient? debugOverrideGisSdkClient, @visibleForTesting StreamController? debugAuthenticationController, - }) : _gisSdkClient = debugOverrideGisSdkClient, - _authenticationController = - debugAuthenticationController ?? - StreamController.broadcast() { + }) : _gisSdkClient = debugOverrideGisSdkClient, + _authenticationController = debugAuthenticationController ?? + StreamController.broadcast() { autoDetectedClientId = web.document .querySelector(clientIdMetaSelector) ?.getAttribute(clientIdAttributeName); @@ -68,8 +67,6 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { // A future that completes when the JS loader is done. late Future _jsSdkLoadedFuture; - // A future that completes when the `init` call is done. - Completer? _initCalled; // A StreamController to communicate status changes from the GisSdkClient. final StreamController _authenticationController; @@ -89,28 +86,14 @@ 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 get initialized { - _assertIsInitCalled(); return Future.wait(>[ _jsSdkLoadedFuture, - _initCalled!.future, ]); } @@ -133,12 +116,8 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { ' or pass clientId when initializing GoogleSignIn', ); - assert( - params.serverClientId == null, - 'serverClientId is not supported on Web.', - ); - - _initCalled = Completer(); + assert(params.serverClientId == null, + 'serverClientId is not supported on Web.'); await _jsSdkLoadedFuture; @@ -149,8 +128,6 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { authenticationController: _authenticationController, loggingEnabled: kDebugMode, ); - - _initCalled!.complete(); // Signal that `init` is fully done. } @override diff --git a/packages/google_sign_in/google_sign_in_web/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/pubspec.yaml index f53d3f0b213..6fa54d1a694 100644 --- a/packages/google_sign_in/google_sign_in_web/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/pubspec.yaml @@ -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.7.0