signInWithGoogle method

Future<GoogleSignInAccount?> signInWithGoogle()

Signs in a user using their Google account.

Initiates a Google sign-in process, retrieves authentication details, and signs the user in with those credentials. Returns the GoogleSignInAccount for the signed-in user.

Implementation

Future<GoogleSignInAccount?> signInWithGoogle() async {
  final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
  final GoogleSignInAuthentication? googleAuth =
      await googleUser?.authentication;
  final credential = GoogleAuthProvider.credential(
    accessToken: googleAuth?.accessToken,
    idToken: googleAuth?.idToken,
  );
  await FirebaseAuth.instance.signInWithCredential(credential);
  return googleUser;
}