Created
June 4, 2019 06:09
-
-
Save Shafran123/fba67cdd44df331b283a3cead80302ef to your computer and use it in GitHub Desktop.
Example code of how to sign in with google.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:google_sign_in/google_sign_in.dart'; | |
import 'package:firebase_auth/firebase_auth.dart'; | |
void _signInWithGoogle() async { | |
final GoogleSignInAccount googleUser = await _googleSignIn.signIn(); | |
final GoogleSignInAuthentication googleAuth = | |
await googleUser.authentication; | |
final AuthCredential credential = GoogleAuthProvider.getCredential( | |
accessToken: googleAuth.accessToken, | |
idToken: googleAuth.idToken, | |
); | |
final FirebaseUser user = await _auth.signInWithCredential(credential); | |
assert(user.email != null); | |
assert(user.displayName != null); | |
assert(!user.isAnonymous); | |
assert(await user.getIdToken() != null); | |
final FirebaseUser currentUser = await _auth.currentUser(); | |
assert(user.uid == currentUser.uid); | |
setState(() { | |
if (user != null) { | |
_success = true; | |
_userID = user.uid; | |
_email = user.email; | |
_name = user.displayName; | |
_ppic = user.photoUrl; | |
return _userID; | |
} else { | |
_success = false; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment