Firebase 无法登录或登录时,将作为消息显示给用户的PlatformException
我需要设置一个警报消息,如果登录失败-提供最准确的根本原因失败给用户 为了确保涵盖所有可能性,我在提交内容中有不同级别的警报 我面临的问题是,此警报无法识别PlatformException errorMessage返回空值 无论我测试的是什么问题,例如错误代码、现有电子邮件等,我都找不到导致出现未定义问题的原因Firebase 无法登录或登录时,将作为消息显示给用户的PlatformException,firebase,flutter,authentication,Firebase,Flutter,Authentication,我需要设置一个警报消息,如果登录失败-提供最准确的根本原因失败给用户 为了确保涵盖所有可能性,我在提交内容中有不同级别的警报 我面临的问题是,此警报无法识别PlatformException errorMessage返回空值 无论我测试的是什么问题,例如错误代码、现有电子邮件等,我都找不到导致出现未定义问题的原因 您应该将catch块中的错误传递给AuthExceptionHandler.generateeExceptionMessage()并从那里显示给用户。 Exception has o
您应该将
catch
块中的错误传递给AuthExceptionHandler.generateeExceptionMessage()
并从那里显示给用户。
Exception has occurred.
PlatformException (PlatformException(ERROR_EMAIL_ALREADY_IN_USE, The email address is already in use by another account., null))
void _submitForm() {
if (!_formKey.currentState.validate()) {
return;
}
_formKey.currentState.save();
try{
AuthNotifier authNotifier = Provider.of<AuthNotifier>(context, listen: false);
final status = login(_user, authNotifier);
if (_authMode == AuthMode.Login) {
login(_user, authNotifier);
print("Signed In with ID");
} else {
signup(_user, authNotifier);
} if (status == AuthResultStatus.successful) {
} else {
final errorMsg = AuthExceptionHandler.generateExceptionMessage(status);
_showAlertDialog(errorMsg);
}
return;
} catch (e) {
print(e);
setState(() {
_warning = e.message;
});
}
}
_showAlertDialog(errorMsg) {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
'Login Failed',
style: TextStyle(color: Colors.black),
),
content: Text(errorMsg),
);
});
}
class AuthExceptionHandler {
static handleException(e) {
print(e.code);
var status;
switch (e.code) {
case "ERROR_INVALID_EMAIL":
status = AuthResultStatus.invalidEmail;
break;
case "ERROR_WRONG_PASSWORD":
status = AuthResultStatus.wrongPassword;
break;
case "ERROR_USER_NOT_FOUND":
status = AuthResultStatus.userNotFound;
break;
case "ERROR_USER_DISABLED":
status = AuthResultStatus.userDisabled;
break;
case "ERROR_TOO_MANY_REQUESTS":
status = AuthResultStatus.tooManyRequests;
break;
case "ERROR_OPERATION_NOT_ALLOWED":
status = AuthResultStatus.operationNotAllowed;
break;
case "ERROR_EMAIL_ALREADY_IN_USE":
status = AuthResultStatus.emailAlreadyExists;
break;
default:
status = AuthResultStatus.undefined;
}
return status;