简体   繁体   English

如何设置flutter注册

[英]How to set up flutter sign up

I have phone authentication set up already, I want to collect the user's name, company name, and location.我已经设置了电话认证,我想收集用户名、公司名和位置。 User signs in to the app and then they have to fill in the remaining details(name, company name, and location).用户登录到应用程序,然后他们必须填写剩余的详细信息(姓名、公司名称和位置)。

Below is the code I have right now, but every time a user signs up and adds his info a new document is created in firebase.下面是我现在拥有的代码,但是每次用户注册并添加他的信息时,都会在 firebase 中创建一个新文档。 The phone number is stored in a different document and the user info is saved in the other.电话号码存储在不同的文档中,用户信息保存在另一个文档中。 What I basically want is to update the same document where the phone number is, so the document holds the phone number and the info!我基本上想要的是更新电话号码所在的同一文档,因此该文档包含电话号码和信息!

Thanks Already!谢谢 已经!

在此处输入图片说明

Flutter Code:颤振代码:

  CollectionReference users = FirebaseFirestore.instance.collection("users");
  String textNote;
  String companyName;

 SizedBox(
          width: 320,
          child: Container(
            child: ElevatedButton(
              onPressed: () async {
                await users.add({
                  'name': textNote,
                  'company name': companyName,
                }).then((value) => print('User Added'))
                ;
              },
              child: Text(
                "SEND",
                style: TextStyle(
                  color: Colors.white,
                ),
              ),
            ),
          ),
        ),

在此处输入图片说明

This line below adds a new document to the users collection:下面这行向 users 集合添加了一个新文档:

await users.add({
  'name': textNote,
  'company name': companyName,
})

if you try to add phone number the same way, it will add it to a new document.如果您尝试以相同的方式添加电话号码,它会将其添加到新文档中。

Rather, you should use set not add .相反,您应该使用set而不是add With set, you can pass the document ID which you want to save the data to (in this case, your user id).使用 set,您可以传递要将数据保存到的文档 ID(在本例中为您的用户 ID)。 eg:例如:

CollectionReference users = FirebaseFirestore.instance.collection("users");

// to add name and company name
// user.uid is the uid of the user.
users.doc(user.uid).set({
  'name': textNote,
  'company name': companyName,
});

// to add phone no;
users.doc(user.uid).set({'phone_no': phone_no}, SetOptions(merge: true));
// NB: Please note the SetOptions which should prevent it from overwriting
// the first data.

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

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