简体   繁体   中英

How to make Flutter sign up with more fields?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM