[英]How to set up flutter sign up
我已经设置了电话认证,我想收集用户名、公司名和位置。 用户登录到应用程序,然后他们必须填写剩余的详细信息(姓名、公司名称和位置)。
下面是我现在拥有的代码,但是每次用户注册并添加他的信息时,都会在 firebase 中创建一个新文档。 电话号码存储在不同的文档中,用户信息保存在另一个文档中。 我基本上想要的是更新电话号码所在的同一文档,因此该文档包含电话号码和信息!
谢谢 已经!
颤振代码:
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,
),
),
),
),
),
下面这行向 users 集合添加了一个新文档:
await users.add({
'name': textNote,
'company name': companyName,
})
如果您尝试以相同的方式添加电话号码,它会将其添加到新文档中。
相反,您应该使用set
而不是add
。 使用 set,您可以传递要将数据保存到的文档 ID(在本例中为您的用户 ID)。 例如:
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.