Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = GoogleSignIn();
Future<FirebaseUser> loginWithGoogle() async {
GoogleSignInAccount currentUser = _googleSignIn.currentUser;
if (currentUser == null) {
currentUser = await _googleSignIn.signInSilently();
if (currentUser == null) {
currentUser = await _googleSignIn.signIn();
if (currentUser == null) {
throw('Login Canceled');
final GoogleSignInAuthentication auth = await currentUser.authentication;
final FirebaseUser user =
await _auth.signInWithCredential(GoogleAuthProvider.getCredential(
idToken: gAuth.idToken,
accessToken: gAuth.accessToken,
assert(user != null);
assert(await user.getIdToken() != null);
return user;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.