1

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

2 Answers 2

2
    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

Sign up to request clarification or add additional context in comments.

1 Comment

I am also facing same issue...... you got solution?? please help
0

You need to import - import 'package:flutter/services.dart';

then try this code:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.