First, add these packages to your .yaml file
firebase_core: ^0.5.0 firebase_auth: ^0.18.0+1 google_sign_in: ^4.5.3
Add key tool path in debug and release mode
signingConfigs {
debug {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
Then use this function on button click
final GoogleSignIn _googleSignIn = GoogleSignIn(); final FirebaseAuth _auth = FirebaseAuth.instance; Future googleSignIn() async { await Firebase.initializeApp(); return await _googleSignIn.signIn().then((value) async { if (value != null) { final GoogleSignInAuthentication googleSignInAuthentication = await value.authentication; final AuthCredential credential = GoogleAuthProvider.credential( accessToken: googleSignInAuthentication.accessToken, idToken: googleSignInAuthentication.idToken, ); final UserCredential authResult = await _auth.signInWithCredential(credential); final User? user = authResult.user; assert(user!.isAnonymous); assert(await user!.getIdToken() != null); final User? currentUser = _auth.currentUser; assert(user!.uid == currentUser!.uid); print(currentUser!.uid); if (currentUser != null) { if (currentUser.displayName != null) { Navigator.push( context, MaterialPageRoute( builder: (context) => HomeScreen(), ), ); } else { Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => AddProfileData())); } } return currentUser; } else { return null; } }); }