signInWithGoogle method
Implementation
Future<SocialLoginDataModel?> signInWithGoogle() async {
try {
GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: <String>[
'email',
'https://www.googleapis.com/auth/contacts.readonly',
],
);
await _googleSignIn.signOut();
final GoogleSignInAccount? googleSignInAccount =
await _googleSignIn.signIn();
if (googleSignInAccount == null) {
return null;
}
GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
AuthCredential googleIdCredential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
final userCredential =
await FirebaseAuth.instance.signInWithCredential(googleIdCredential);
User? firebaseUser = userCredential.user;
return SocialLoginDataModel(
socialId: googleSignInAccount.id,
firebaseAuthUser: firebaseUser,
errorMessage: _successConst,
status: true);
} catch (e) {
log("e---------->$e");
displayError(e);
return SocialLoginDataModel(
socialId: null,
firebaseAuthUser: null,
errorMessage: "${e.toString()}",
status: false);
}
}