Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I catch Flutter Google sign-in PlatformException?

Following the brilliant Firebase Flutter tutorial, I'm trying to incorporate Google sign-in into my app.

The flow: If not logged in, user will always arrive at login page (via checks at the MaterialApp's onGenerateRoute), user then presses the Login button and redirected to the Google sign-in flow. However, should the user cancel the flow midway, I'd like to return to the login page, forcing her to press the button again.

I fail to catch the PlatformException for some reason (you can see it in the debugger, and the app hanging in the simulator): the exception in the debugger, the app hangs in the simulator

The code I'm using:

  Future<bool> logIn() async {
    print('Login::logIn()');
    bool loggedIn = await logInSilently();
    print('Login::logIn() - silent login returned $loggedIn');
    if (loggedIn == false) {
      try {
        await googleSignIn.signIn();
      } catch (e) {
        print('Login::logIn() - interactive login failed: $e');
        return false;
      }
    }
    return true;
  }

The print statement inside the catch block is never printed, and the app hangs. I've upgraded flutter and re-tested before posting the question - the issue is still there.

(To clarify: The "happy path" -- i.e. user successfully going through the Google sign-in flow -- works.)

like image 299
Yaya Avatar asked Jun 24 '17 19:06

Yaya


People also ask

How do you integrate Google sign into Flutter app?

Step 1: First create the flutter project in your IDE. Step 2: After that just remove the default code and start from scratch. Step 3: Now just import the material library and call the runApp( ) function into the main function name as GoogleSignIn. Step 4: Now make a stateful widget with the name 'GoogleSignIn'.

What is Platform exception flutter?

PlatformException class Null safetyThrown to indicate that a platform interaction failed in the platform plugin.


1 Answers

I believe this was fixed in google_sign_in version 0.2.1.

Try putting changing your google_sign_in dependency in your pubspec.yaml to ^0.2.1 and see if that helps.

like image 175
Collin Jackson Avatar answered Sep 23 '22 07:09

Collin Jackson