如何从 firestore 获取数据并显示在数据 table 中? [扑]
How to get data from firestore and show in data table? [Flutter]
情况: 在提交页面,用户必须select协会名称(下拉菜单),输入标题,附加文件,然后提交。用户提交文件后,文件将存储在 firebase 存储中,firestore 将详细信息保存在 collection("Society Name") > document("date").
下
详细信息:文件标题、提交日期、用户 ID、Url ...
期望:我希望用户可以查看提交文件的详细信息,页面将显示他们所属的协会,以及显示详细信息的数据table(列:文件标题、提交日期)。
目前,我可以显示当前用户的社会,使用future builder,从用户详细信息中获取文档快照。但是我不知道如何从 collection("Society Name") 中获取文档 id("information" 除外),因为我存储的文档 id 是日期时间格式,假设会有超过 1 个文档 id , 存储提交文件的详细信息。
问题:如何获取所有文档ID(“信息”除外)并在数据中显示详细信息table?列表视图也接受table.
如果有人能帮助我或给我一些指导,我将不胜感激。谢谢
据我了解,您想获取集合中的所有 documents id
。为此,您需要一个查询来获取集合中的所有文档。
QuerySnapshot snapshot = await FirebaseFirestore.instance.collection('Society Name').get();
List docs = snapshot.docs;
获取所有文档后,您现在可以循环列表以从 DocumentSnapshot
.
获取 id
docs.forEach((doc){
print(doc.id);
});
官方文档供您参考:
id → String
This document's given ID for this snapshot.
https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/DocumentSnapshot-class.html
要呈现为列表小部件,您可以将 ListView.builder
与 FutureBuilder
一起使用
情况: 在提交页面,用户必须select协会名称(下拉菜单),输入标题,附加文件,然后提交。用户提交文件后,文件将存储在 firebase 存储中,firestore 将详细信息保存在 collection("Society Name") > document("date").
下详细信息:文件标题、提交日期、用户 ID、Url ...
期望:我希望用户可以查看提交文件的详细信息,页面将显示他们所属的协会,以及显示详细信息的数据table(列:文件标题、提交日期)。
目前,我可以显示当前用户的社会,使用future builder,从用户详细信息中获取文档快照。但是我不知道如何从 collection("Society Name") 中获取文档 id("information" 除外),因为我存储的文档 id 是日期时间格式,假设会有超过 1 个文档 id , 存储提交文件的详细信息。
问题:如何获取所有文档ID(“信息”除外)并在数据中显示详细信息table?列表视图也接受table.
如果有人能帮助我或给我一些指导,我将不胜感激。谢谢
据我了解,您想获取集合中的所有 documents id
。为此,您需要一个查询来获取集合中的所有文档。
QuerySnapshot snapshot = await FirebaseFirestore.instance.collection('Society Name').get();
List docs = snapshot.docs;
获取所有文档后,您现在可以循环列表以从 DocumentSnapshot
.
id
docs.forEach((doc){
print(doc.id);
});
官方文档供您参考:
id → String This document's given ID for this snapshot. https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/DocumentSnapshot-class.html
要呈现为列表小部件,您可以将 ListView.builder
与 FutureBuilder