signInWithGoogle method
Implementation
@override
Future<Response<Credential>> signInWithGoogle() async {
final response = Response<Credential>();
try {
GoogleSignInAccount? result;
final auth = googleAuth;
final isSignedIn = await auth.isSignedIn();
if (isSignedIn) {
result = await auth.signInSilently();
} else {
result = await auth.signIn();
}
if (result != null) {
final authentication = await result.authentication;
final idToken = authentication.idToken;
final accessToken = authentication.accessToken;
if (accessToken != null || idToken != null) {
final receivedData = auth.currentUser;
return response.withData(Credential(
id: receivedData?.id,
email: receivedData?.email,
name: receivedData?.displayName,
photo: receivedData?.photoUrl,
accessToken: accessToken,
idToken: idToken,
credential: GoogleAuthProvider.credential(
idToken: idToken,
accessToken: accessToken,
),
));
} else {
return response.withException(
'Token not valid!',
status: Status.error,
);
}
} else {
return response.withException('Sign in failed!', status: Status.error);
}
} on FirebaseAuthException catch (_) {
return response.withException(_.message, status: Status.failure);
}
}