Error Handling

The default behaviour for error handling is to present the error to the user in a Snackbar. In case you want to customize the text of the message you can easily to it.

In this example, we will change the 'user-not-found' firebase error message.

First of all, extend the AuthMethod whose error message you want to override.

  1. First of all, extend the AuthMethod whose error message you want to override.

  2. Now override errMsg method and provide your own message.

class CustomErrorMessage extends Email {
  CustomErrorMessage({@required EmailConfig config}) : super(config: config);

  @override
  String errMsg(e, bool isFirebaseException, FirebaseExceptionData fe) {
    if (isFirebaseException) {
      switch (fe.code) {
        case 'user-not-found':
          // Default message is 'There is no user record corresponding to this identifier. Please create an account'
          // We change it to 'Please create an Account'
          return 'Please create an account';
          break;
        default:
      }
    }

    return null;
  }
}

3. Now pass it to SignIn Widget.

SignIn(
        themeColor: Colors.deepPurple,
        // here 
        methods: [ CustomErrorMessage(config: EmailConfig())],
        auth: FirebaseAuth.instance,
        onSuccess: (user, context, fields) {
          showSnackBar(
              'You made the signUp flow in record time. Cheers.', context);
          print('user: $user \n fields: $fields');
        },
      )

Shew. Lot of hardwork.

Last updated