How to make Flutter sign up with more fields?

Viewed 2205

My sign up page has the following fields Names, password, confirm password and email but it seems flutter firebase only works for email and password. How do I make more fields work in the below code:

createUser()async{
    if (checkFields()){
      await FirebaseAuth.instance.createUserWithEmailAndPassword(email: _email, password: _password)
          .then((user){
        print('signed in as ${user.uid}');

        Navigator.push(context, MaterialPageRoute(builder: (context)=> (Usertype())));

      }).catchError((e){
        print(e);
      });
    }
  }
1 Answers

Unfortunately, you cannot make Firebase accept Names on sign up event. But you can update user information after sign up.

Use updateProfile method after authentication is successfully complete. You can check this as Android example, and here as the method from the Flutter package.

In your case,

createUser()async{
    if (checkFields()){
      await FirebaseAuth.instance.createUserWithEmailAndPassword(email: _email, password: _password)
          .then((user){
        print('signed in as ${user.uid}');
        var userUpdateInfo = new UserUpdateInfo(); //create user update object
        userUpdateInfo.displayName = name; //set user display name to your variable.
        await firebaseAuth.updateProfile(userUpdateInfo); //update the info
        await user.reload(); //reload the user data

        Navigator.push(context, MaterialPageRoute(builder: (context)=> (Usertype())));

      }).catchError((e){
        print(e);
      });
    }
  }
Related