skip to Main Content

I am using the firebase_ui_auth: ^1.12.1 package to show SignInScreen but I can’t find a way to display a custom message when an error occurs. If, for example, the user enters wrong credentials, I get an exception and a long, not very user-friendly message shows.

SignInScreen(
    providers: providers,
    actions: [
        AuthStateChangeAction<SignedIn>((context, state) {
            Navigator.pushReplacementNamed(context, '/profile');
        }),
    ],
);

How can I show a different message or modify how the error message show?

SignInScreen error message

2

Answers


  1.  try {
            await FirebaseAuth.instance.signInWithEmailAndPassword(
                email: emailController.text, password: passwordController.text);
    
           
          }  catch (error) {
            var e = error as FirebaseAuthException;
            Print(e.message!);
          }
    

    Try this.

    Login or Signup to reply.
  2. There is a class you can use for that. It’s also explained in the official document also.

     ErrorText
     A widget that displays error text for a given Firebase error code. 
    

    Check this out example:

    ErrorText.localizeError = (BuildContext context, FirebaseAuthException e) {
      final defaultLabels = FirebaseUILocalizations.labelsOf(context);
    
      return switch (e.code) {
        'user-not-found' => 'Please create an account first.',
        'credential-already-in-use' => 'This email is already in use.',
        _ => localizedErrorText(e.code, defaultLabels) ?? 'Oh no! Something went wrong.',
      }
    }
    

    Or the network errors:

    ErrorText.localizePlatformError = (BuildContext context, PlatformException e) {
      if (e.code == "network_error") return "Please check your internet connection.";
      return "Oh no! Something went wrong.";
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search