loginWithGoogle method
Future<void>
loginWithGoogle(
)
Implementation
Future<void> loginWithGoogle() async {
final googleSign = GoogleSignIn(scopes: ['profile', 'email']);
GoogleSignInAccount? account = await googleSign.signInSilently();
account ??= await googleSign.signIn();
final auth = await account?.authentication;
final cred = GoogleAuthProvider.credential(
idToken: auth?.idToken,
accessToken: auth?.accessToken,
);
final userCred = await _firebaseAuth.signInWithCredential(cred);
final response = await _dioApiService.post(
endpoint: '${CommunityConstants.socialAuth}/google',
body: {"access_token": cred.accessToken, "project": 'quitmate'},
headers: {'api-key': CommunityConstants.apiKey},
);
if (response.statusCode == 200) {
await Hive.box('user_data').put('user_token', response.data['token']);
user.value = userCred.user;
if (user.value != null) {
isSignedIn.value = true;
_onLogin();
}
}
}