Skip to content

Commit 60afd33

Browse files
Update google_sign_in version (#2339)
Upgrade the version of `google_sign_in` ## Pre-launch Checklist - [x] I read the [Effective Dart: Style] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. <!-- Links --> [Effective Dart: Style]: https://dart.dev/guides/language/effective-dart/style [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
1 parent d9bcf96 commit 60afd33

File tree

41 files changed

+1184
-715
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1184
-715
lines changed

.github/workflows/flutter-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26-
flutter_version: [stable, beta, master]
26+
flutter_version: [stable, beta, main]
2727
os: [ubuntu-latest, macos-latest, windows-latest]
2828
steps:
2929
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

adaptive_app/codelab_rebuild.yaml

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,9 +1314,9 @@ steps:
13141314
- name: flutter pub get
13151315
path: adaptive_app
13161316
flutter: pub get
1317-
- name: Add googleapis_auth google_sign_in extension_google_sign_in_as_googleapis_auth
1317+
- name: Add googleapis_auth google_sign_in extension_google_sign_in_as_googleapis_auth logging
13181318
path: adaptive_app
1319-
flutter: pub add googleapis_auth google_sign_in:^6.3.0 extension_google_sign_in_as_googleapis_auth:^2.0.13
1319+
flutter: pub add googleapis_auth google_sign_in extension_google_sign_in_as_googleapis_auth logging
13201320
- name: Patch .gitignore
13211321
path: adaptive_app/.gitignore
13221322
patch-u: |
@@ -1336,6 +1336,7 @@ steps:
13361336
// Use of this source code is governed by a BSD-style license that can be
13371337
// found in the LICENSE file.
13381338
1339+
import 'dart:async';
13391340
import 'dart:io' show Platform;
13401341
13411342
import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart';
@@ -1344,11 +1345,14 @@ steps:
13441345
import 'package:go_router/go_router.dart';
13451346
import 'package:google_sign_in/google_sign_in.dart';
13461347
import 'package:googleapis_auth/auth_io.dart';
1348+
import 'package:logging/logging.dart';
13471349
import 'package:provider/provider.dart';
13481350
import 'package:url_launcher/link.dart';
13491351
13501352
import 'app_state.dart';
13511353
1354+
final _log = Logger('AdaptiveLogin');
1355+
13521356
typedef _AdaptiveLoginButtonWidget =
13531357
Widget Function({required VoidCallback? onPressed});
13541358
@@ -1395,29 +1399,52 @@ steps:
13951399
@override
13961400
initState() {
13971401
super.initState();
1398-
_googleSignIn = GoogleSignIn(scopes: widget.scopes);
1399-
_googleSignIn.onCurrentUserChanged.listen((account) {
1400-
if (account != null) {
1401-
_googleSignIn.authenticatedClient().then((authClient) {
1402-
final context = this.context;
1403-
if (authClient != null && context.mounted) {
1404-
context.read<AuthedUserPlaylists>().authClient = authClient;
1405-
context.go('/');
1406-
}
1407-
});
1402+
_googleSignIn = GoogleSignIn.instance;
1403+
_googleSignIn.initialize();
1404+
_authEventsSubscription = _googleSignIn.authenticationEvents.listen((
1405+
event,
1406+
) async {
1407+
_log.fine('Google Sign-In authentication event: $event');
1408+
if (event is GoogleSignInAuthenticationEventSignIn) {
1409+
final googleSignInClientAuthorization = await event
1410+
.user
1411+
.authorizationClient
1412+
.authorizationForScopes(widget.scopes);
1413+
if (googleSignInClientAuthorization == null) {
1414+
_log.warning('Google Sign-In authenticated client creation failed');
1415+
return;
1416+
}
1417+
_log.fine('Google Sign-In authenticated client created');
1418+
final context = this.context;
1419+
if (context.mounted) {
1420+
context.read<AuthedUserPlaylists>().authClient =
1421+
googleSignInClientAuthorization.authClient(scopes: widget.scopes);
1422+
context.go('/');
1423+
}
14081424
}
14091425
});
1426+
1427+
// Check if user is already authenticated
1428+
_log.fine('Attempting lightweight authentication');
1429+
_googleSignIn.attemptLightweightAuthentication();
1430+
}
1431+
1432+
@override
1433+
dispose() {
1434+
_authEventsSubscription.cancel();
1435+
super.dispose();
14101436
}
14111437
14121438
late final GoogleSignIn _googleSignIn;
1439+
late final StreamSubscription _authEventsSubscription;
14131440
14141441
@override
14151442
Widget build(BuildContext context) {
14161443
return Scaffold(
14171444
body: Center(
14181445
child: widget.button(
14191446
onPressed: () {
1420-
_googleSignIn.signIn();
1447+
_googleSignIn.authenticate();
14211448
},
14221449
),
14231450
),

adaptive_app/step_03/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1919
version: 1.0.0+1
2020

2121
environment:
22-
sdk: ^3.9.0-0
22+
sdk: ^3.9.0
2323

2424
# Dependencies specify other packages that your package needs in order to work.
2525
# To automatically upgrade your package dependencies to the latest versions

0 commit comments

Comments
 (0)