signInWithGoogle method

Future<void> signInWithGoogle({
  1. required BuildContext context,
})

Implementation

Future<void> signInWithGoogle({required BuildContext context}) async {
  if (kIsWeb) {
    GoogleAuthProvider googleProvider = GoogleAuthProvider();

    // Once signed in, return the UserCredential
    FirebaseAuth.instance.signInWithPopup(googleProvider).then((value) {
      loginWithUserCredential(context: context, userCredential: value);
    }).catchError((err) {
      showError(err: err, context: context);
//show the error
    });
  }
  // Trigger the authentication flow
  final googleUser = await GoogleSignIn().signIn();

  // Obtain the auth details from the request
  final GoogleSignInAuthentication googleAuth =
      await googleUser!.authentication;

  // Create a new credential
  final credential = GoogleAuthProvider.credential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );

  // Once signed in, return the UserCredential
  FirebaseAuth.instance.signInWithCredential(credential).then((value) {
    loginWithUserCredential(context: context, userCredential: value);
  }).catchError((err) {
    showError(err: err, context: context);
//show the error
  });
}