signInWithGoogle method
Future<User?>
signInWithGoogle(
- BuildContext context, {
- Color? progressBarColors,
- bool? isDisplayProgressBar,
Implementation
Future<User?> signInWithGoogle(BuildContext context,
{Color? progressBarColors, bool? isDisplayProgressBar}) async {
ProgressDialog.show(context,progressBarColors??Colors.black,isDisplayProgressBar??false);
// await signOut();
if (googleSignInAccount != null) {
await _googleSignIn.disconnect();
await FirebaseAuth.instance.signOut();
}
googleSignInAccount = await _googleSignIn.signIn();
if(googleSignInAccount!=null){
GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount!.authentication;
AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
return await FirebaseAuth.instance.signInWithCredential(credential).then((UserCredential result){
// Map userData=new Map();
ProgressDialog.hide();
// userData["email"]=result.user?.email;
// userData["displayName"]=result.user?.displayName;
// userData["uid"]=result.user?.uid;
print("userData="+result.user.toString());
// loginAPI(context,result.user.email,"",LoginType.google.name,result.user.uid,result.user.displayName);
print("return userData main");
return result.user;
}).catchError((e){
print(e.toString());
String errorMessage;
switch (e.code) {
case "ERROR_INVALID_EMAIL":
errorMessage = "Your email address appears to be malformed.";
break;
case "ERROR_WRONG_PASSWORD":
errorMessage = "Your password is wrong.";
break;
case "ERROR_USER_NOT_FOUND":
errorMessage = "User with this email doesn't exist.";
break;
case "ERROR_USER_DISABLED":
errorMessage = "User with this email has been disabled.";
break;
case "ERROR_TOO_MANY_REQUESTS":
errorMessage = "Too many requests. Try again later.";
break;
case "ERROR_OPERATION_NOT_ALLOWED":
errorMessage = "Signing in with Email and Password is not enabled.";
break;
default:
errorMessage = "An undefined Error happened.";
}
if(errorMessage!=null){
showToastMessage(errorMessage);
}
ProgressDialog.hide();
print("return userData error");
return null;
});
}else{
ProgressDialog.hide();
// showToastMessage("Something went wrong");
print("return userData else");
return null;
/* Future.delayed(Duration(seconds: 1)).then((valuess) {
ProgressDialog.hide();
});*/
}
print("return userData end");
// return user;
}