Skip to content

Commit 4b2132f

Browse files
authored
[google_sign_in/google_identity_services] Clear-up documentation of callbacks in various APIs and uses of those APIs (#8029)
These APIs used to accept allowInterop'd callbacks. When the implementation was migrated to use dart:js_interop, they were wrapped with toJS. However, starting in 3.5, to be consistent with dart2wasm, double-wrapping a function is an error. The documentation should be clear that it accepts only Dart functions and uses should be cleaned up to not use allowInterop and type the callbacks' parameter and return value correctly.
1 parent da51281 commit 4b2132f

File tree

9 files changed

+25
-23
lines changed

9 files changed

+25
-23
lines changed

packages/google_identity_services_web/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
## NEXT
1+
## 0.3.1+5
22

33
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
4+
* Cleans up documentation of callbacks in `CodeClientConfig`,
5+
`TokenClientConfig`, `onGoogleLibraryLoad`, and `revoke` to indicate they only
6+
accept Dart functions and not JS functions.
47

58
## 0.3.1+4
69

packages/google_identity_services_web/example/integration_test/js_interop_oauth_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ void main() async {
2626
testWidgets('TokenClientConfig', (_) async {
2727
final TokenClientConfig config = TokenClientConfig(
2828
client_id: 'testing_1-2-3',
29-
callback: (_) {},
29+
callback: (TokenResponse _) {},
3030
scope: <String>['one', 'two', 'three'],
3131
include_granted_scopes: true,
3232
prompt: 'some-prompt',
3333
enable_granular_consent: true,
3434
login_hint: '[email protected]',
3535
hd: 'hd_value',
3636
state: 'some-state',
37-
error_callback: (_) {},
37+
error_callback: (GoogleIdentityServicesError? _) {},
3838
);
3939

4040
final utils.ExpectConfigValueFn expectConfigValue =
@@ -79,14 +79,14 @@ void main() async {
7979
scope: <String>['one', 'two', 'three'],
8080
include_granted_scopes: true,
8181
redirect_uri: Uri.parse('https://www.example.com/login'),
82-
callback: (_) {},
82+
callback: (CodeResponse _) {},
8383
state: 'some-state',
8484
enable_granular_consent: true,
8585
login_hint: '[email protected]',
8686
hd: 'hd_value',
8787
ux_mode: UxMode.popup,
8888
select_account: true,
89-
error_callback: (_) {},
89+
error_callback: (GoogleIdentityServicesError? _) {},
9090
);
9191

9292
final utils.ExpectConfigValueFn expectConfigValue =
@@ -110,7 +110,7 @@ void main() async {
110110
testWidgets('returns a tokenClient', (_) async {
111111
final TokenClient client = oauth2.initTokenClient(TokenClientConfig(
112112
client_id: 'for-tests',
113-
callback: (_) {},
113+
callback: (TokenResponse _) {},
114114
scope: <String>['some_scope', 'for_tests', 'not_real'],
115115
));
116116

packages/google_identity_services_web/lib/src/js_interop/google_accounts_id.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ extension GoogleAccountsIdExtension on GoogleAccountsId {
164164
/// ID is the `sub` property of the [CredentialResponse.credential] payload.
165165
///
166166
/// The optional [callback] is a function that gets called to report on the
167-
/// success of the revocation call.
167+
/// success of the revocation call. It must be a Dart function and not a JS
168+
/// function.
168169
///
169170
/// Method: google.accounts.id.revoke
170171
/// https://developers.google.com/identity/gsi/web/reference/js-reference#google.accounts.id.revoke

packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extension GoogleAccountsOauth2Extension on GoogleAccountsOauth2 {
7373
/// A valid [accessToken] is required to revoke permissions.
7474
///
7575
/// The [done] callback is called once the revoke action is done. It must be
76-
/// manually wrapped in [allowInterop] before being passed to this method.
76+
/// a Dart function and not a JS function.
7777
///
7878
/// Method: google.accounts.oauth2.revoke
7979
/// https://developers.google.com/identity/oauth2/web/reference/js-reference#google.accounts.oauth2.revoke
@@ -103,8 +103,7 @@ extension GoogleAccountsOauth2Extension on GoogleAccountsOauth2 {
103103
abstract class CodeClientConfig {
104104
/// Constructs a CodeClientConfig object in JavaScript.
105105
///
106-
/// The [callback] property must be wrapped in [allowInterop] before it's
107-
/// passed to this constructor.
106+
/// The [callback] property must be a Dart function and not a JS function.
108107
factory CodeClientConfig({
109108
required String client_id,
110109
required List<String> scope,
@@ -230,8 +229,7 @@ typedef CodeClientCallbackFn = void Function(CodeResponse response);
230229
abstract class TokenClientConfig {
231230
/// Constructs a TokenClientConfig object in JavaScript.
232231
///
233-
/// The [callback] property must be wrapped in [allowInterop] before it's
234-
/// passed to this constructor.
232+
/// The [callback] property must be a Dart function and not a JS function.
235233
factory TokenClientConfig({
236234
required String client_id,
237235
required TokenClientCallbackFn callback,
@@ -315,9 +313,6 @@ extension TokenClientExtension on TokenClient {
315313
@staticInterop
316314
abstract class OverridableTokenClientConfig {
317315
/// Constructs an OverridableTokenClientConfig object in JavaScript.
318-
///
319-
/// The [callback] property must be wrapped in [allowInterop] before it's
320-
/// passed to this constructor.
321316
factory OverridableTokenClientConfig({
322317
/// A list of scopes that identify the resources that your application could
323318
/// access on the user's behalf. These values inform the consent screen that

packages/google_identity_services_web/lib/src/js_interop/load_callback.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ external set _onGoogleLibraryLoad(JSFunction callback);
2323

2424
/// Method called after the Sign In With Google JavaScript library is loaded.
2525
///
26-
/// The [callback] parameter must be manually wrapped in [allowInterop]
27-
/// before being set to the [onGoogleLibraryLoad] property.
26+
/// The [function] parameter must be a Dart function and not a JS function.
2827
set onGoogleLibraryLoad(VoidFn function) {
2928
_onGoogleLibraryLoad = function.toJS;
3029
}

packages/google_identity_services_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_identity_services_web
22
description: A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_identity_services_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_identiy_services_web%22
5-
version: 0.3.1+4
5+
version: 0.3.1+5
66

77
environment:
88
sdk: ^3.4.0

packages/google_sign_in/google_sign_in_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.12.4+3
2+
3+
* Fixes callback types for `TokenClientConfig`.
4+
15
## 0.12.4+2
26

37
* Adds support for `web: ^1.0.0`.

packages/google_sign_in/google_sign_in_web/lib/src/gis_client.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ class GisSdkClient {
188188
//
189189
// Token clients have an additional `error_callback` for miscellaneous
190190
// errors, like "popup couldn't open" or "popup closed by user".
191-
void _onTokenError(Object? error) {
191+
void _onTokenError(GoogleIdentityServicesError? error) {
192192
if (error != null) {
193-
_tokenResponses.addError((error as GoogleIdentityServicesError).type);
193+
_tokenResponses.addError(error.type);
194194
}
195195
}
196196

@@ -223,9 +223,9 @@ class GisSdkClient {
223223
}
224224
}
225225

226-
void _onCodeError(Object? error) {
226+
void _onCodeError(GoogleIdentityServicesError? error) {
227227
if (error != null) {
228-
_codeResponses.addError((error as GoogleIdentityServicesError).type);
228+
_codeResponses.addError(error.type);
229229
}
230230
}
231231

packages/google_sign_in/google_sign_in_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
33
for signing in with a Google account on Android, iOS and Web.
44
repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_web
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
6-
version: 0.12.4+2
6+
version: 0.12.4+3
77

88
environment:
99
sdk: ^3.3.0

0 commit comments

Comments
 (0)