I am trying to implement Google Sign In in my android flutter app, but I have this problem:
When user cancel Google sign in (tap on back button) this exception is throw.
PlatformException (PlatformException(sign_in_canceled, com.google.android.gms.common.api.ApiException: 12501: , null))
I found that from some newer version this should be fixed and it should return null instead of an exception. Currently I am using google_sign_in: ^4.1.1
I tried to wrap my code inside try-catch block or using .catchError() on the method, but nothing help.
My code looks like this:
Future googleSign(BuildContext context) async {
final GoogleSignInAccount googleSignInAccount =
await googleSignIn.signIn().catchError((onError) => print(onError));
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
final AuthResult authResult = await _auth.signInWithCredential(credential);
return authResult.user.uid;
}
Do you have any idea, how to handle this exception? Thanks.