Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit c3b12da

Browse files
committed
Address PR feedback
1 parent e1ebf7d commit c3b12da

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,13 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
2929
.querySelector(_kClientIdMetaSelector)
3030
?.getAttribute(_kClientIdAttributeName);
3131

32-
_isGapiInitialized =
33-
gapi.inject(gapiUrl).then((_) => gapi.init()).then((_) {
34-
isInitialized = true;
35-
});
32+
_isGapiInitialized = gapi.inject(gapiUrl).then((_) => gapi.init());
3633
}
3734

3835
Future<void> _isGapiInitialized;
3936

4037
@visibleForTesting
41-
Future<void> get isInitializing => _isGapiInitialized;
42-
43-
@visibleForTesting
44-
bool isInitialized = false;
38+
Future<void> get initialized => _isGapiInitialized;
4539

4640
String _autoDetectedClientId;
4741
FutureOr<auth2.GoogleUser> _lastSeenUser;
@@ -69,7 +63,7 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
6963
'Check https://developers.google.com/identity/protocols/googlescopes '
7064
'for a list of valid OAuth 2.0 scopes.');
7165

72-
await _isGapiInitialized;
66+
await initialized;
7367

7468
final auth2.GoogleAuth auth = auth2.init(auth2.ClientConfig(
7569
hosted_domain: hostedDomain,
@@ -97,22 +91,22 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
9791

9892
@override
9993
Future<GoogleSignInUserData> signInSilently() async {
100-
await _isGapiInitialized;
94+
await initialized;
10195

10296
return gapiUserToPluginUserData(await _lastSeenUser);
10397
}
10498

10599
@override
106100
Future<GoogleSignInUserData> signIn() async {
107-
await _isGapiInitialized;
101+
await initialized;
108102

109103
return gapiUserToPluginUserData(await auth2.getAuthInstance().signIn());
110104
}
111105

112106
@override
113107
Future<GoogleSignInTokenData> getTokens(
114108
{@required String email, bool shouldRecoverAuth}) async {
115-
await _isGapiInitialized;
109+
await initialized;
116110

117111
final auth2.GoogleUser currentUser =
118112
auth2.getAuthInstance()?.currentUser?.get();
@@ -124,14 +118,14 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
124118

125119
@override
126120
Future<void> signOut() async {
127-
await _isGapiInitialized;
121+
await initialized;
128122

129123
return auth2.getAuthInstance().signOut();
130124
}
131125

132126
@override
133127
Future<void> disconnect() async {
134-
await _isGapiInitialized;
128+
await initialized;
135129

136130
final auth2.GoogleUser currentUser =
137131
auth2.getAuthInstance()?.currentUser?.get();
@@ -140,7 +134,7 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
140134

141135
@override
142136
Future<bool> isSignedIn() async {
143-
await _isGapiInitialized;
137+
await initialized;
144138

145139
final auth2.GoogleUser currentUser =
146140
auth2.getAuthInstance()?.currentUser?.get();
@@ -149,7 +143,7 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
149143

150144
@override
151145
Future<void> clearAuthCache({String token}) async {
152-
await _isGapiInitialized;
146+
await initialized;
153147

154148
_lastSeenUser = null;
155149
return auth2.getAuthInstance().disconnect();

packages/google_sign_in/google_sign_in_web/test/auth2_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main() {
2929

3030
setUp(() async {
3131
plugin = GoogleSignInPlugin();
32-
await plugin.isInitializing;
32+
await plugin.initialized;
3333
});
3434

3535
test('Init requires clientId', () async {

packages/google_sign_in/google_sign_in_web/test/gapi_load_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ void main() {
2626
isNotNull,
2727
reason: 'Mock script should be injected',
2828
);
29-
await plugin.isInitializing;
29+
await plugin.initialized;
3030
expect(
31-
plugin.isInitialized,
32-
isTrue,
33-
reason: 'Plugin is initialized after awaiting the isInitializing future',
31+
plugin.initialized,
32+
completes,
33+
reason: 'The plugin should complete the future once initialized.',
3434
);
3535
});
3636
}

0 commit comments

Comments
 (0)