Home > Mobile >  flutter FireBase email&pass auth null value
flutter FireBase email&pass auth null value

Time:07-31

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

CodePudding user response:

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.

CodePudding user response:

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);

  • Related