Dart 异常Firebase Auth on Flatter,使用vccode
我正在开发一个登录系统,使用firebase、Flatter和vscode 我想知道如何处理Firebase生成的异常。 如果电子邮件已经注册 当前正在生成错误:Dart 异常Firebase Auth on Flatter,使用vccode,dart,flutter,Dart,Flutter,我正在开发一个登录系统,使用firebase、Flatter和vscode 我想知道如何处理Firebase生成的异常。 如果电子邮件已经注册 当前正在生成错误: Exception has occurred. PlatformException (PlatformException(ERROR_EMAIL_ALREADY_IN_USE, The email address is already in use by another account., null)) 如果电子邮件已经注册,我想通
Exception has occurred.
PlatformException (PlatformException(ERROR_EMAIL_ALREADY_IN_USE, The email address is already in use by another account., null))
如果电子邮件已经注册,我想通知用户
代码:
未来注册({@required-Map-userData、@required-String-pass、@required-VoidCallback-onSuccess、@required-VoidCallback-onFail})异步{
isLoading=true;
notifyListeners();
_auth.createUserWithEmailAndPassword(
电子邮件:userData[“电子邮件”],
密码:pass
).then((用户)异步{
firebaseUser=用户;
wait_saveUserData(userData);
onSuccess();
isLoading=false;
notifyListeners();
}).catchError((e){
印刷品(e);
onFail();
isLoading=false;
notifyListeners();
});
}
使用平台上的异常捕获(e)
和if(e.message=='ERROR\u EMAIL\u ready\u use')
来处理此情况。如果您想在发出ERROR\u EMAIL\u ready\u use时执行后续操作
我认为捕获平台异常并使用code
分支流程是一个好主意,如下所示
try {
final result = await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
} on PlatformException catch (exception) {
switch (exception.code) {
case 'ERROR_EMAIL_ALREADY_IN_USE':
// do something...
default:
break;
}
有人能解决这个问题吗?
try {
final result = await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
} on PlatformException catch (exception) {
switch (exception.code) {
case 'ERROR_EMAIL_ALREADY_IN_USE':
// do something...
default:
break;
}