How can I read the data of my Firebase document and put the data in a local list/array?
CodePudding user response:
To get all data from Firestore.
FirebaseFirestore.instance
.collection("users")
.get()
.then((value) {
print(value.docs);
for (var element in value.docs) {
print(element.id);// you will get all ids here
}
});
If you want to upload one particular data from Firestore.
FirebaseFirestore.instance
.collection("users")
.where("uid",
isEqualTo: 'your_uid')
.get()
.then((value) {
print(value.docs);
for (var element in value.docs) {
print(element.id); // single id of that collection
}
});
CodePudding user response:
I have tried this once.... check if this is the same u looking for
List<String> list=[];
final snapshot = await FirebaseFirestore.instance
.collection("users").get();
for(int x=0;x<snapshot.docs.length;x )
{
list.add(snapshot.docs[x].id);
}
print(list);