Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Appease lint
  • Loading branch information
ditman committed Nov 13, 2019
commit edbdff357060fcbad63bc3e170d7161581ee3364
44 changes: 26 additions & 18 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 @@ -76,8 +76,8 @@ class GoogleSignInAccount implements GoogleIdentity {
throw StateError('User is no longer signed in.');
}

final GoogleSignInTokenData response =
await GoogleSignInPlatform.instance.getTokens(email: email, shouldRecoverAuth: true);
final GoogleSignInTokenData response = await GoogleSignInPlatform.instance
.getTokens(email: email, shouldRecoverAuth: true);

// On Android, there isn't an API for refreshing the idToken, so re-use
// the one we obtained on login.
Expand Down Expand Up @@ -147,10 +147,14 @@ class GoogleSignIn {
/// The [hostedDomain] argument specifies a hosted domain restriction. By
/// setting this, sign in will be restricted to accounts of the user in the
/// specified domain. By default, the list of accounts will not be restricted.
GoogleSignIn({this.signInOption = SignInOption.standard, this.scopes = const <String>[], this.hostedDomain});
GoogleSignIn(
{this.signInOption = SignInOption.standard,
this.scopes = const <String>[],
this.hostedDomain});

/// Factory for creating default sign in user experience.
factory GoogleSignIn.standard({List<String> scopes = const <String>[], String hostedDomain}) {
factory GoogleSignIn.standard(
{List<String> scopes = const <String>[], String hostedDomain}) {
return GoogleSignIn(
signInOption: SignInOption.standard,
scopes: scopes,
Expand Down Expand Up @@ -215,15 +219,14 @@ class GoogleSignIn {
}

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

/// The most recently scheduled method call.
Expand All @@ -244,7 +247,8 @@ class GoogleSignIn {
///
/// At most one in flight call is allowed to prevent concurrent (out of order)
/// updates to [currentUser] and [onCurrentUserChanged].
Future<GoogleSignInAccount> _addMethodCall(Function method, {bool canSkipCall = false}) async {
Future<GoogleSignInAccount> _addMethodCall(Function method,
{bool canSkipCall = false}) async {
Future<GoogleSignInAccount> response;
if (_lastMethodCall == null) {
response = _callMethod(method);
Expand Down Expand Up @@ -287,7 +291,8 @@ class GoogleSignIn {
Future<GoogleSignInAccount> signInSilently(
{bool suppressErrors = true}) async {
try {
return await _addMethodCall(GoogleSignInPlatform.instance.signInSilently, canSkipCall: true);
return await _addMethodCall(GoogleSignInPlatform.instance.signInSilently,
canSkipCall: true);
} catch (_) {
if (suppressErrors) {
return null;
Expand All @@ -314,16 +319,19 @@ class GoogleSignIn {
///
/// Re-authentication can be triggered only after [signOut] or [disconnect].
Future<GoogleSignInAccount> signIn() {
final Future<GoogleSignInAccount> result = _addMethodCall(GoogleSignInPlatform.instance.signIn, canSkipCall: true);
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);
}

/// Marks current user as being in the signed out state.
Future<GoogleSignInAccount> signOut() => _addMethodCall(GoogleSignInPlatform.instance.signOut);
Future<GoogleSignInAccount> signOut() =>
_addMethodCall(GoogleSignInPlatform.instance.signOut);

/// Disconnects the current user from the app and revokes previous
/// authentication.
Future<GoogleSignInAccount> disconnect() => _addMethodCall(GoogleSignInPlatform.instance.disconnect);
Future<GoogleSignInAccount> disconnect() =>
_addMethodCall(GoogleSignInPlatform.instance.disconnect);
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ void main() {
GoogleSignIn googleSignIn;

setUp(() {
MethodChannelGoogleSignIn platformInstance = GoogleSignInPlatform.instance;
final MethodChannelGoogleSignIn platformInstance =
GoogleSignInPlatform.instance;
platformInstance.channel.setMockMethodCallHandler(
(FakeSignInBackend()..user = kUserData).handleMethodCall);
googleSignIn = GoogleSignIn();
Expand Down