Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
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/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.5.4

* Fix `PlatformException` leaking in debug mode.

## 4.5.3

* Update package:e2e -> package:integration_test
Expand Down
41 changes: 25 additions & 16 deletions packages/google_sign_in/google_sign_in/lib/google_sign_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,18 @@ class GoogleSignIn {
return _currentUser;
}

Future<void> _ensureInitialized() {
return _initialization ??= GoogleSignInPlatform.instance.init(
signInOption: signInOption,
scopes: scopes,
hostedDomain: hostedDomain,
clientId: clientId,
)..catchError((dynamic _) {
// Invalidate initialization if it errors out.
_initialization = null;
});
Future<void> _ensureInitialized() async {
try {
return _initialization ??= GoogleSignInPlatform.instance.init(
signInOption: signInOption,
scopes: scopes,
hostedDomain: hostedDomain,
clientId: clientId,
);
} catch (_) {
// Invalidate initialization if it errors out.
_initialization = null;
}
}

/// The most recently scheduled method call.
Expand Down Expand Up @@ -354,12 +356,19 @@ class GoogleSignIn {
/// a Future which resolves to the same user instance.
///
/// Re-authentication can be triggered only after [signOut] or [disconnect].
Future<GoogleSignInAccount> signIn() {
final Future<GoogleSignInAccount> result =
_addMethodCall(GoogleSignInPlatform.instance.signIn, canSkipCall: true);
bool isCanceled(dynamic error) =>
error is PlatformException && error.code == kSignInCanceledError;
return result.catchError((dynamic _) => null, test: isCanceled);
Future<GoogleSignInAccount> signIn() async {
try {
return await _addMethodCall(GoogleSignInPlatform.instance.signIn,
canSkipCall: true);
} catch (e) {
bool isCanceled(dynamic error) =>
error is PlatformException && error.code == kSignInCanceledError;

if (isCanceled(e)) {
return null;
}
rethrow;
}
}

/// Marks current user as being in the signed out state.
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_sign_in
description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android and iOS.
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
version: 4.5.3
version: 4.5.4

flutter:
plugin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ void main() {
]);
});

test('signIn canceled returns a null user', () async {
channel.setMockMethodCallHandler((MethodCall methodCall) {
throw PlatformException(code: GoogleSignIn.kSignInCanceledError);
});
expect(await googleSignIn.signIn(), isNull); // should not throw
});

test('disconnect; null response', () async {
await googleSignIn.disconnect();
expect(googleSignIn.currentUser, isNull);
Expand Down Expand Up @@ -307,7 +314,7 @@ void main() {
throw "I am an error";
});
expect(googleSignIn.signInSilently(suppressErrors: false),
throwsA(isInstanceOf<PlatformException>()));
throwsA(isA<PlatformException>()));
});

test('can sign in after init failed before', () async {
Expand All @@ -321,8 +328,8 @@ void main() {
}
return Future<dynamic>.value(responses[methodCall.method]);
});
expect(googleSignIn.signIn(), throwsA(isInstanceOf<PlatformException>()));
expect(await googleSignIn.signIn(), isNotNull);
expect(googleSignIn.signIn(), throwsA(isA<PlatformException>()));
expect(await googleSignIn.signIn(), isA<GoogleSignInAccount>());
});

test('created with standard factory uses correct options', () async {
Expand Down