skip to Main Content

I’m experiencing an issue with Google Sign-In in my Flutter application. When attempting to sign in with Google, I receive a PlatformException. Here’s the error log:

W/Auth    (10169): [GoogleAuthUtil] [GoogleAuthUtil] error status:UNKNOWN with method:getTokenWithDetails
...
I/flutter (10169): error: PlatformException(exception, ERROR, null, null)
E/flutter (10169): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(exception, ERROR, null, null)
E/flutter (10169): #0 GoogleSignInApi.getAccessToken (package:google_sign_in_android/src/messages.g.dart:250:7)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #1 GoogleSignInAndroid.getTokens.<anonymous closure> (package:google_sign_in_android/google_sign_in_android.dart:68:15)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #2 GoogleSignInAccount.authentication (package:google_sign_in/google_sign_in.dart:95:9)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #3 GoogleLoginProvider.getAuthCredential (package:firebase_manager/src/auth/login/providers/google_login_provider.dart:15:11)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #4 LoginTool.loginByGoogle (package:firebase_manager/src/auth/login/login_tool.dart:36:37)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #5 StatePage.build.<anonymous closure> (package:saiwai/ui/loginpage/login_page.dart:80:42)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169):

I’ve tried the following steps to resolve the issue:

  1. Updated all dependencies to their latest versions
  2. Checked and updated the SHA-1 fingerprint in the Firebase console
  3. Verified the Firebase configuration files (google-services.json)
  4. flutter clean

Despite these efforts, the error persists. I’m using the latest stable version of Flutter and testing on an Android device.

Here’s a snippet of my code where the error occurs:

  Future<OAuthCredential?> getAuthCredential() async {
    // Trigger the authentication flow
    final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
    if (googleUser != null) {
      // Obtain the auth details from the request
      final GoogleSignInAuthentication googleAuth =
          await googleUser.authentication;
      // Create a new credential
      return GoogleAuthProvider.credential(
        accessToken: googleAuth.accessToken,
        idToken: googleAuth.idToken,
      );
    }
    return null;
  }

Can anyone suggest what might be causing this issue or how to further diagnose and resolve it? Any help would be greatly appreciated.

2

Answers


  1. similar problem, yesterday this code still worked, today it doesn’t, in all my applications that I haven’t updated for several months with this code they show an error:

    static Future<void> signInWithGoogle(BuildContext context) async {
        try {
          final connectivityResult = await (Connectivity().checkConnectivity());
          if (connectivityResult == ConnectivityResult.none) {
            ScaffoldMessenger.of(context).showSnackBar(
              const SnackBar(content: Text('Check your internet connection and try again.')),
            );
            return;
          }
    
          await googleSignIn.signOut();
    
          final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
          log('Google User: ${googleUser?.email}');
    
          if (googleUser == null) {
            log('Google Sign-In canceled');
            return;
          }
    
          final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
          log('Google Authentication: ${googleAuth.accessToken}, ${googleAuth.idToken}');
    
          final AuthCredential credential = GoogleAuthProvider.credential(
            accessToken: googleAuth.accessToken,
            idToken: googleAuth.idToken,
          );
          log('Google Credentials: ${credential.providerId}');
    
          final UserCredential userCredential = await auth.signInWithCredential(credential);
          final User? user = userCredential.user;
    
          if (user != null) {
            await addUserToFirestore(user);
    
            if (context.mounted) {
              Navigator.pushReplacement(
                context,
                MaterialPageRoute(builder: (context) => const HomeScreen()),
              );
            }
          }
        } catch (e) {
          if (e is FirebaseAuthException) {
            log('FirebaseAuthException: ${e.code} - ${e.message}');
          } else if (e is PlatformException) {
            log('PlatformException: ${e.code} - ${e.message} - ${e.details}');
          } else {
            log('Error during Google Sign-In: $e');
          }
          if (context.mounted) {
            ScaffoldMessenger.of(context).showSnackBar(
              SnackBar(content: Text('Login error: ${e.toString()}')),
            );
          }
        }
      }
    

    [log] PlatformException: exception – ERROR – null

    Login or Signup to reply.
  2. This worked for me

    GoogleSignInAuthentication? googleSignInAuthentication =
        await (await GoogleSignIn(
        scopes: ["profile", "email"],
    ).signIn())
        ?.authentication;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search