Home > Mobile >  Where am I wrong? The code never catch an exception while trying to createUserWithEmailAndPassword
Where am I wrong? The code never catch an exception while trying to createUserWithEmailAndPassword

Time:10-02

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'))
                ],
              );
            },
          );

CodePudding user response:

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

CodePudding user response:

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

thank you....

  • Related