I am using the following code to sign in with Google using firebase authentication.
Future<bool> signInWithGoogle(context) async {
// Trigger the authentication flow
bool signedIn = true;
final GoogleSignInAccount googleUser = await GoogleSignIn().signIn()
.catchError((error){
//ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(error)));
signedIn = false;
});
// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth = await googleUser.authentication
.catchError((onError)=> signedIn = false);
// Create a new credential
final GoogleAuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Once signed in, return the UserCredential
UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
firebaseUser = userCredential.user;
return signedIn;
}
Most of the time my code works fine but at times I get an error in the console which I am not sure of. I need help in resolving this error and understanding the root of this.
The error is as follows:
E/flutter (26892): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: type 'bool' is not a subtype of type 'FutureOr<GoogleSignInAccount>'
E/flutter (26892): #0 _FutureListener.handleError (dart:async/future_impl.dart:160:20)
E/flutter (26892): #1 Future._propagateToListeners.handleError (dart:async/future_impl.dart:708:47)
E/flutter (26892): #2 Future._propagateToListeners (dart:async/future_impl.dart:729:24)...
...
question from:
https://stackoverflow.com/questions/66054677/error-signing-in-with-google-using-firebaseauthemtication 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…