阅读firebase文档并将数据复制到dart列表中



如何读取Firebase文档的数据并将数据放入本地列表/数组?

我的火球文档

从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

}
});

如果您想从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

}
});

我已经试过一次了。。。。检查这是否与寻找的u相同


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);

最新更新