Skip to content
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
3 changes: 1 addition & 2 deletions app_flutter/lib/service/google_authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GoogleSignInService {
final GoogleSignIn _googleSignIn;

/// Whether or not the application has been signed in to.
bool get isAuthenticated => user != null;
Future<bool> get isAuthenticated => _googleSignIn.isSignedIn();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't want to change the getter signature you may be able to do:

bool get isAuthenticated => await _googleSignIn.isSignedIn();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(You might need to change it to an async fn, so maybe you still need to change the signature after all, hmmm)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The await expression can only be used in an async function.
Try marking the function body with either 'async' or 'async*'


/// The Google Account for the signed in user, null if no user is signed in.
///
Expand All @@ -57,6 +57,5 @@ class GoogleSignInService {

Future<void> signOut() async {
await _googleSignIn.signOut();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No action required, just want to mention that it's amusing to see "SignIn.signOut" :)

user = null;
}
}
55 changes: 30 additions & 25 deletions app_flutter/lib/sign_in_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,36 @@ class SignInButton extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (authService.isAuthenticated) {
return PopupMenuButton<String>(
// TODO(chillers): Switch to use avatar widget provided by google_sign_in plugin
child: Image.network(authService.user.photoUrl),
offset: const Offset(0, 50),
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'logout',
child: Text('Log out'),
),
],
onSelected: (String value) {
if (value == 'logout') {
authService.signOut();
}
},
);
}

return FlatButton(
child: const Text(
'Sign in',
style: TextStyle(color: Colors.white),
),
onPressed: () => authService.signIn(),
return FutureBuilder<bool>(
future: authService.isAuthenticated,
builder: (BuildContext context, AsyncSnapshot<bool> isAuthenticated) {
/// On sign out, there's a second where the user is null before isAuthenticated catches up.
if (isAuthenticated.data && authService.user != null)
return PopupMenuButton<String>(
// TODO(chillers): Switch to use avatar widget provided by google_sign_in plugin
child: Image.network(authService.user?.photoUrl),
offset: const Offset(0, 50),
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'logout',
child: Text('Log out'),
),
],
onSelected: (String value) {
if (value == 'logout') {
authService.signOut();
}
},
);
else
return FlatButton(
child: const Text(
'Sign in',
style: TextStyle(color: Colors.white),
),
onPressed: () => authService.signIn(),
);
},
);
}
}