【问题标题】:Exception Firebase Auth on flutter, using vccodeFlutter中的异常Firebase Auth,使用vscode
【发布时间】:2019-09-10 04:09:17
【问题描述】:

我正在开发一个登录系统,使用 firebase、flutter 和 vscode。

我想知道如何处理 Firebase 生成的异常。 如果 EMAIL 已经注册。

当前产生错误:

Exception has occurred.
PlatformException (PlatformException(ERROR_EMAIL_ALREADY_IN_USE, The email address is already in use by another account., null))

如果邮箱已经注册,我想通知用户。

代码:

Future<void> signUp({@required Map<String, dynamic> userData,@required String pass,@required VoidCallback onSuccess,@required VoidCallback onFail}) async{
    isLoading = true;
    notifyListeners();

    _auth.createUserWithEmailAndPassword(
      email: userData["email"],
      password: pass
    ).then((user) async{
      firebaseUser = user;
      await _saveUserData(userData);
      onSuccess();
      isLoading = false;
      notifyListeners();
    }).catchError((e){

      print(e);
      onFail();
      isLoading = false;
      notifyListeners();
    });

  }

【问题讨论】:

  • 有没有人可以解决这个问题?

标签: dart flutter


【解决方案1】:

如果您想在发出 ERROR_EMAIL_ALREADY_IN_USE 时执行后续操作。

我认为捕获 PlatformException 并使用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;
}

【讨论】:

    【解决方案2】:

    使用on PlatformException catch (e)(e.message == 'ERROR_EMAIL_ALREADY_IN_USE') 来处理这种情况。

    【讨论】:

      猜你喜欢
      • 2020-07-17
      • 2022-12-31
      • 2022-09-25
      • 2021-01-12
      • 2022-10-14
      • 2021-07-14
      • 2021-06-27
      • 2020-10-27
      • 2021-04-22
      相关资源
      最近更新 更多