首页 > 解决方案 > 在 Flutter / Firebase Auth 注册中捕获错误

问题描述

我在flutter中从firebase身份验证实例中捕获错误时遇到了一些麻烦,我不知道出了什么问题,即使我发现了错误,代码仍然会抛出异常,此外,我不知道如何识别异常类型是否是格式错误的电子邮件、已在使用的电子邮件、弱密码等......并且没有适当的文档说明此类事情

我试过这个:

    FirebaseAuth.instance.createUserWithEmailAndPassword(
       email: _email, password: _password)
           .then((currentUser) => {
              //Execute            
         }).catchError((onError)=>{
              print(onError)
          });

并尝试了一个简单的 try-catch 块,但没有一个能捕捉到异常

标签: firebaseflutterfirebase-authentication

解决方案


    FirebaseAuth.instance.createUserWithEmailAndPassword(
          email: _email, password: _password)
              .then((currentUser) => {
                 //Execute            
             }).catchError((onError)=>{
                  //Handle error i.e display notification or toast
              });

此代码确实有效,但编辑器(Visual Studio 代码)本身会引发异常并使应用程序崩溃,如果您从设备或模拟器本身运行应用程序,问题将得到解决


推荐阅读