0

I'm creating an app in Flutter using both the Firebase Authentication plugin as well as the RT Database plugin. The concept is that the user inputs some simple data such as their name, email, phone and password and signs up for an account. The authentication plugin saves the email and password for authentication later on the login screen (this works). What I want to have happen, however, is for the other data (specifically the name and email address) to be saved to the RT Database, which I will call on later on another screen in a list view. I'm using the "UID" and "authResult" as a means to accomplish this, however, I'm getting the following errors anywhere "uid" is in my code...

"The property 'uid' can't be unconditionally accessed because the receiver can be 'null'."

ElevatedButton( child: Text('Sign Up'), style: ElevatedButton.styleFrom( fixedSize: Size(100, 10), backgroundColor: const Color.fromRGBO(0, 33, 115, 2), ), onPressed: () { FirebaseAuth.instance .createUserWithEmailAndPassword( email: emailController.text, password: passwordController.text) .then((authResult) { var userProfile = { 'uid': authResult.user.uid, 'name': nameController.text, 'email': emailController, };

                FirebaseDatabase.instance
                    .ref()
                    .child("students/" + authResult.user.uid)
                    .set(userProfile)
                    .then((value) {
                  print("Successfully created the profile information");
                }).catchError((error) {
                  print("Failed to create profile information");
                });
              }).catchError((error) {
                print('Failed to sign up user');
                print(error.toString());
              });
            },
          ),

I've tried using a null check, Flutter also suggests using ?. as well as interpolation. ?. cleared the error on the variable but not the Firebase instance. Using interpolation cleared the error on the FB instance but it didn't work.

ST30
  • 23
  • 3

0 Answers0