How to Handle Firebase Auth exceptions on flutter

前端 未结 12 1124
走了就别回头了
走了就别回头了 2020-11-30 07:56

Please does anyone know how to catch firebase Auth exceptions on flutter and display them?

Note: I am not interested in the console (catcherror((e) print(e))

12条回答
  •  忘掉有多难
    2020-11-30 08:12

    in Dart you can react to different Exceptions using the on syntax. Since Firebase uses its own PlatformException you can easily catch them with:

      try {
          AuthResult result = await signUp(email, password);
      } on PlatformException catch (e) {
          print(e.message);
      } on Exception catch (e) {
          print(e);
      }
    

    PlatformException brings a code as well as a message which can be displayed in the UI, i.e. :

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

提交回复
热议问题