bizz84 / firebase_auth_demo_flutter

Reference Authentication Flow with Flutter & Firebase
https://codewithandrea.com/
MIT License
674 stars 178 forks source link

App crashes when I click close from google sign in #23

Closed springfitnesstechnology closed 5 years ago

springfitnesstechnology commented 5 years ago

I am trying to get the 'Sign in aborted by user.' dialog box to show when I close the Google Sign In. Right now when I click close the app crashes and this is what appears:

Exception has occurred.

PlatformException (PlatformException(sign_in_canceled, com.google.GIDSignIn, The user canceled the sign-in flow.))

The line appears on the following line of code in the Auth.dart file:

GoogleSignInAccount googleUser = await googleSignIn.signIn();

Just to test the functionality of the dialog box, I changed the if statement in auth.dart from:

if (googleUser != null)

to

if (googleUser == null)

This results in the dialog box appearing. So throwing the PlatformException must be working correctly. It seems like the problem is that the app crashes before the program checks if the user is null.

I have even tried directly catching the error like this:

GoogleSignInAccount googleUser;
      try {
        googleUser = await googleSignIn.signIn();
      } catch (e) {
        throw PlatformException(
          code: "ERROR_ABORTED_BY_USER",
          message: 'Sign in aborted by user.',
          );
      }

 I think that googleSignIn.signIn() might be returning an exception instead of null, but I have the same version as the videos.

springfitnesstechnology commented 5 years ago

Update: This functionality works when I run it from android studios, but does not work when I run it from visual studios... Does anyone know why this could be?

bizz84 commented 5 years ago

After testing, I can confirm that this happens on VS Code but not on Android Studio.

When running the app without debugging in VS Code, the app behaves correctly. That is, I can cancel the Google Sign-in page, and a PlatformException is caught and handled by the app.

So the issue is due to how the IDE is configured to handle Dart exceptions.

In fact, a breakpoint is triggered even in Android Studio if the debugger is configured to do so:

dart-exception-breakpoint

In VS code, exception breakpoints can be configured in the Debug View. In this case, unselecting the Uncaught exceptions option makes the issue go away:

vs-code-uncaught-exceptions

What is strange is that this should not be an uncaught exception at all, as it is handled by the app.

springfitnesstechnology commented 5 years ago

Oh that’s weird, thank you!

bizz84 commented 5 years ago

Closing this - feel free to reopen if there are still issues.