Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 异常Firebase Auth on Flatter,使用vccode_Dart_Flutter - Fatal编程技术网

Dart 异常Firebase Auth on Flatter,使用vccode

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)) 如果电子邮件已经注册,我想通

我正在开发一个登录系统,使用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))
如果电子邮件已经注册,我想通知用户

代码:

未来注册({@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;
}