简体   繁体   中英

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. 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:

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 . With set, you can pass the document ID which you want to save the data to (in this case, your user 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.

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