skip to Main Content

i have a question when sending the value for auth. to firebase from elevated button , the terminal giving Null check operator used on a null value , my code as below :

onPressed: () async {
                      try {
                        var auth = FirebaseAuth.instance;
                        UserCredential user =
                            await auth.createUserWithEmailAndPassword(
                          email: emailAddress!,
                          password: password!,
                        );
                        print(user.user!.displayName);
                      } on FirebaseAuthException catch (e) {
                        if (e.code == 'weak-password') {
                          print('The password provided is too weak.');
                        } else if (e.code == 'email-already-in-use') {
                          print('The account already exists for that email.');
                        }
                      } catch (e) {
                        print(e);
                      }
                    },

2

Answers


  1. Chosen as BEST ANSWER

    i added controller for the textfield and assigned them as strings to the email and password , then removed one line which is wrong in the main.dart

    await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);


  2. That happens because the email address and password variables are null.

    The ! operator tells flutter that you are sure those values are not null. But if they are it throws an exception ("Null check operator used on a null value" in your case).

    I advise you to verify that the emailAddress and password variables are initialized and get a value before you call the createUserWithEmailAndPassword methode.

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