Skip to content

Sign In with Google documentation is outdated. #1234

@abrahamcft360

Description

@abrahamcft360

Code: Future signInWithGoogle() async {
try {

  const webClientId = 'xxxxx';
  const iosClientId = 'xxxxx';


  final GoogleSignIn googleSignIn = GoogleSignIn(
    clientId: iosClientId,
    serverClientId: webClientId,
  );
  final googleUser = await googleSignIn.signIn();
  final googleAuth = await googleUser!.authentication;
  final accessToken = googleAuth.accessToken;
  final idToken = googleAuth.idToken;

  if (accessToken == null) {
    throw 'No Access Token found.';
  }
  if (idToken == null) {
    throw 'No ID Token found.';
  }

  final response = await client.auth.signInWithIdToken(
    provider: OAuthProvider.google,
    idToken: idToken,
    accessToken: accessToken,
  );

  if (response.user != null) {
    return await _handleSocialSignIn(user: response.user!, authMethod: 'google');
  } else {
    return AuthResult.error('Google sign-in failed. Please try again.');
  }
} on AuthException catch (e) {
  log('❌ AuthException during Google Sign-In: ${e.message}');
  return AuthResult.error('Could not sign in with Google. ${e.message}');
} on Exception catch (e) {
  log('❌ General Exception during Google Sign-In: $e');
  return AuthResult.error(
    'An unexpected error occurred. Please try again.',
  );
}

}


Getting exceptions like:

  1. The class 'GoogleSignIn' doesn't have an unnamed constructor.
    Try using one of the named constructors defined in 'GoogleSignIn'.

  2. The method 'signIn' isn't defined for the type 'GoogleSignIn'.
    Try correcting the name to the name of an existing method, or defining a method named 'signIn'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions