Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch platformException in flutter/dart?

I am getting

Exception has occurred. PlatformException (PlatformException(sign_in_canceled, com.google.android.gms.common.api.ApiException: 12501: , null))

whenever I try to cancel login with google pop up in my app.

STEP TO REPRODUCE:

In the app when pressed login with google button the google sign in page appears with all the gmail accounts to choose from to login or signup.

Touch the outer area of the pop up to cancel the sign in , which then shuts down the pop up.

After that there is platform exception in the code saying :

Exception has occurred. PlatformException (PlatformException(sign_in_canceled, com.google.android.gms.common.api.ApiException: 12501: , null))

Now the login button is not working and the app crashes,

Tried try/catch - not working

like image 494
Nirvik Basnet Avatar asked May 10 '19 15:05

Nirvik Basnet


1 Answers

try {
  final res = await _auth.signInWithEmailAndPassword(
      email: email, password: password);
  if (res != null) loggedUser = res.user;
} on PlatformException catch (err) {
  // Handle err
} catch (err) {
  // other types of Exceptions
}
like image 118
Oscarreño Avatar answered Sep 19 '22 15:09

Oscarreño