Ad

Catching Errors In Flutter / Firebase Auth Sign Up

I'm having a bit of trouble catching errors from firebase authentication instances in flutter , I don't know what is wrong the code still throws exceptions even though i'm catching the errors , In addition , I have no idea how to identify the exception type whether its a badly formatted email , email already in use , weak password , etc.... and there is no proper documentation for such thing

I have tried this:

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

And tried a simple try-catch block and none of them catch the exception

Ad

Answer

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

This code actually works but the editor (Visual Studio code) itself is throwing exceptions and crashing the app , if you run the app from the device or emulator itself the issue will be solved

Ad
source: stackoverflow.com
Ad