skip to Main Content

Please direct how to catch firebase auth Exception. I have used already added emails to sign up, console shows error messages but I could not catch the error by try-catch method.

Future signUp() async {
        final isValid = formKey.currentState!.validate();
        if (!isValid) return;
        showDialog(
            context: context,
            builder: (context) => const CircularProgressIndicator(
                  strokeWidth: 2,`enter code here`
                ));
        try {
          FirebaseAuth.instance.createUserWithEmailAndPassword(
            email: emailController.text.trim(),
            password: confirmPasswordController.text.trim(),
          );
        } on FirebaseAuthException catch (e) {
          showDialog(
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                title: const Text('Error'),
                content: Text('${e.message}'),
                actions: [
                  TextButton(
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                      child: const Text('Ok'))
                ],
              );
            },
          );

2

Answers


  1. Chosen as BEST ANSWER

    I have removed --- formkey.currentstate.validate(). Now its working

    thank you....


  2. Here you can read about how to catch errors from firebase
    ُError Handling

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search