简体   繁体   English

如何使Flutter注册更多字段?

[英]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. 我的注册页面包含以下字段:名称,密码,确认密码和电子邮件,但flutter firebase似乎仅适用于电子邮件和密码。 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. 不幸的是,您不能使Firebase在注册事件时接受Names But you can update user information after sign up. 但是,您可以在注册后更新用户信息。

Use updateProfile method after authentication is successfully complete. 身份验证成功完成后,请使用updateProfile方法。 You can check this as Android example, and here as the method from the Flutter package. 您可以将作为Android示例进行检查, 在此处作为Flutter软件包中的方法进行检查。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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