Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/flutter-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
fail-fast: false
matrix:
flutter_version: [stable, beta, master]
flutter_version: [stable, beta, main]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand Down
53 changes: 40 additions & 13 deletions adaptive_app/codelab_rebuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,9 @@ steps:
- name: flutter pub get
path: adaptive_app
flutter: pub get
- name: Add googleapis_auth google_sign_in extension_google_sign_in_as_googleapis_auth
- name: Add googleapis_auth google_sign_in extension_google_sign_in_as_googleapis_auth logging
path: adaptive_app
flutter: pub add googleapis_auth google_sign_in:^6.3.0 extension_google_sign_in_as_googleapis_auth:^2.0.13
flutter: pub add googleapis_auth google_sign_in extension_google_sign_in_as_googleapis_auth logging
- name: Patch .gitignore
path: adaptive_app/.gitignore
patch-u: |
Expand All @@ -1336,6 +1336,7 @@ steps:
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:io' show Platform;

import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart';
Expand All @@ -1344,11 +1345,14 @@ steps:
import 'package:go_router/go_router.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:googleapis_auth/auth_io.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/link.dart';

import 'app_state.dart';

final _log = Logger('AdaptiveLogin');

typedef _AdaptiveLoginButtonWidget =
Widget Function({required VoidCallback? onPressed});

Expand Down Expand Up @@ -1395,29 +1399,52 @@ steps:
@override
initState() {
super.initState();
_googleSignIn = GoogleSignIn(scopes: widget.scopes);
_googleSignIn.onCurrentUserChanged.listen((account) {
if (account != null) {
_googleSignIn.authenticatedClient().then((authClient) {
final context = this.context;
if (authClient != null && context.mounted) {
context.read<AuthedUserPlaylists>().authClient = authClient;
context.go('/');
}
});
_googleSignIn = GoogleSignIn.instance;
_googleSignIn.initialize();
_authEventsSubscription = _googleSignIn.authenticationEvents.listen((
event,
) async {
_log.fine('Google Sign-In authentication event: $event');
if (event is GoogleSignInAuthenticationEventSignIn) {
final googleSignInClientAuthorization = await event
.user
.authorizationClient
.authorizationForScopes(widget.scopes);
if (googleSignInClientAuthorization == null) {
_log.warning('Google Sign-In authenticated client creation failed');
return;
}
_log.fine('Google Sign-In authenticated client created');
final context = this.context;
if (context.mounted) {
context.read<AuthedUserPlaylists>().authClient =
googleSignInClientAuthorization.authClient(scopes: widget.scopes);
context.go('/');
}
}
});

// Check if user is already authenticated
_log.fine('Attempting lightweight authentication');
_googleSignIn.attemptLightweightAuthentication();
}

@override
dispose() {
_authEventsSubscription.cancel();
super.dispose();
}

late final GoogleSignIn _googleSignIn;
late final StreamSubscription _authEventsSubscription;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: widget.button(
onPressed: () {
_googleSignIn.signIn();
_googleSignIn.authenticate();
},
),
),
Expand Down
2 changes: 1 addition & 1 deletion adaptive_app/step_03/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ^3.9.0-0
sdk: ^3.9.0

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