Reputation: 15
I am trying to create a simple flutter app where a user can add/unfriend other users. I am using the createUserWithEmailAndPassword for registration. Email and name fields are accepted through textform fields and generated in the firestore database using FirebaseAuthAPI() signUp. However, I also want each new user to have empty array fields (which is where I'll be storing their friends), but I have no idea how. This is what my database will be like:
Upvotes: 0
Views: 157
Reputation: 46
you can just add the user using the normal FirebaseAuthAPI() signUp and use ".then()" function which will return the document id for you to add array
summary: create document > return the doc id > add array by doc Id
Edit: add code
// Add a new document with a generated id.
final data = {"name": "Tokyo", "country": "Japan"};
db.collection("cities").add(data).then((documentSnapshot) {
final docId = documentSnapshot.id;
print("Document id: $docId")
//you can do it like this
db.collection("cities").document(docId) //add your code
}
);
Upvotes: 1