'Unhandled Exception: PlatformException(exception, BAD_REQUEST, null, null) - Google Sign In Flutter

I'm implementing Google sign-in and running into this error. I've tried the SHA Keys solution, but it didn't work. I'm running it on an android phone.

googleSignIn = GoogleSignIn();

final googleUser = await googleSignIn.signIn().catchError((onError) {
  debugPrint("Error $onError");
});

GoogleSignInAuthentication googleAuth = await googleUser.authentication; //Error on this line of code 

E/flutter (12062): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(exception, BAD_REQUEST, null, null)
E/flutter (12062): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (12062): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
E/flutter (12062): <asynchronous suspension>
E/flutter (12062): #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:377:43)
E/flutter (12062): <asynchronous suspension>
E/flutter (12062): #3      GoogleSignInAccount.authentication (package:google_sign_in/google_sign_in.dart:96:9)
E/flutter (12062): <asynchronous suspension>
E/flutter (12062): #4      GoogleSignInProvider.googleLogin (package:project/Providers/GoogleSignInProvider.dart:31:45)
E/flutter (12062): <asynchronous suspension>


Solution 1:[1]

Go this route

  Future googleLogin() async {
try {
  final googleUser = await googleSignIn.signIn();
  if (googleUser == null) return;
  _user = googleUser;

  final googleAuth = await googleUser.authentication;
  final credential = GoogleAuthProvider.credential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );

  await FirebaseAuth.instance.signInWithCredential(credential);
} catch (e) {}
notifyListeners();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Saheed