I am using google sign in and firebase to integrate authentication to my app. However I am facing the problem that, when I cancel the sign in (in the sense that I dismiss the popup), I get a
PlatformException (PlatformException(sign_in_canceled, com.google.GIDSignIn, The user canceled the sign-in flow.))
To my knowledge this is supposed to occur, though I am facing the problem that I am not able to catch the error. Here are a few ways in which I have tried to catch this error:
Future loginWithGoogle() async {
final GoogleSignIn googleSignIn = GoogleSignIn();
var account;
try {
account = await googleSignIn.signIn();
} on PlatformException catch (e) {
print('\n\n\n\n\n AN ERROR OCCURED \n\n\n\n\n');
print(e.message);
}
final AuthResult result = await _auth
.signInWithCredential(GoogleAuthProvider.getCredential(
idToken: (await account.authentication).idToken, accessToken: (await account.authentication).accessToken));
setState(() {
_firestore.collection('Users').document('${result.user.uid}').setData({
'Profile Picture': result.user.photoUrl,
'Name': result.user.displayName,
'Email ID': result.user.email,
'Phone Number': result.user.phoneNumber,
});
isAuthenticating = true;
});
if (result.user.phoneNumber == null) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => PhoneRegistrationScreen(
result: result,
),
),
);
}
}
It doesn't print anything when the error occurs. I have also tried to catch the error with the catchError() callback :
account = await googleSignIn.signIn().catchError((error) {
print('AN ERROR OCCURED');
});
Again, it doesn't print anything when the error occurs.
Thanks a lot guys, and I really appreciate your help!