signInWithGoogle method
Implementation
Future<void> signInWithGoogle({String? redirect}) async {
try {
businessController.showDialogProgress(show: true);
var firebaseAuth = FirebaseAuth.instance;
UserCredential userCredential;
if (CheckPlatform().isWeb) {
GoogleAuthProvider googleProvider = GoogleAuthProvider();
userCredential = await firebaseAuth.signInWithPopup(googleProvider);
} else {
// Trigger the authentication flow
final GoogleSignInAccount? googleSignInAccount =
await GoogleSignIn().signIn();
// Obtain the auth details from the request
final GoogleSignInAuthentication? googleAuth =
await googleSignInAccount?.authentication;
// Create a new credential
final OAuthCredential googleAuthCredential =
GoogleAuthProvider.credential(
accessToken: googleAuth?.accessToken,
idToken: googleAuth?.idToken,
);
// Once signed in, get the credential
userCredential =
await firebaseAuth.signInWithCredential(googleAuthCredential);
}
UserModel user = UserModel();
//currentUser = userCredential.user;
user = await userRepository.getUserUI(currentUser: userCredential.user);
user.userName =
TypeSafeConversion.nullSafeString(userCredential.user?.email);
user.motDePasse = user.userName;
user.userCreated = 'google';
//currentUserSink.add(userCredential.user);
//isEmailVerified = userCredential.user!.emailVerified);
await loginRegisterProvider(redirect: redirect, user: user);
} on PlatformException catch (ex, trace) {
logCat('code:${ex.code} | message:${ex.message}');
businessController.showDialogProgress(show: false);
DialogView.showAlertDialog(msg: getErrorMessage(ex));
logError(ex, trace: trace, position: 'signInWithGoogle');
signOut();
update();
} on Exception catch (ex, trace) {
DialogView.showAlertDialog(msg: 'msg_TraitementImpossible'.tr);
businessController.showDialogProgress(show: false);
logError(ex, trace: trace, position: 'signInWithGoogle');
signOut();
} catch (ex, trace) {
logError(ex, trace: trace, position: 'signInWithGoogle');
signOut();
}
businessController.showDialogProgress(show: false);
}