[英]How to get data from firestore and show in data table? [Flutter]
Situation: In submission page, user have to select society name (dropdown menu), enter title, attach file, and submit it.情况:在提交页面,用户必须输入 select 协会名称(下拉菜单),输入标题,附加文件,然后提交。 After user submit the file, the file will be stored in firebase storage, and firestore will save the details under collection("Society Name") > document("date").用户提交文件后,文件将存储在 firebase 存储中,firestore 将详细信息保存在 collection("Society Name") > document("date") 下。
Details: File Title, Submission Date, User Id, Url...详细信息:文件标题、提交日期、用户 ID、Url...
Expectation: I expecting user can check the details of document submitted, the page will show society they belongs to, and a data.table showing details (column: File Title, Submission Date).期望:我希望用户可以查看提交文件的详细信息,页面将显示他们所属的协会,以及显示详细信息的 data.table(列:文件标题,提交日期)。
Currently, I can display the current user's society, using future builder, document snapshot from user details.目前,我可以显示当前用户的社会,使用未来的建设者,来自用户详细信息的文档快照。 But I have no idea how to get the document id (except "information") from collection("Society Name"), because the document id I stored in date time format, assume there will be more than 1 document id, storing details about file submitted.但是我不知道如何从集合(“社会名称”)中获取文档ID(“信息”除外),因为我以日期时间格式存储的文档ID,假设会有超过1个文档ID,存储有关的详细信息提交的文件。
Problem: How can I get the all document id (except "information") and show the details in data.table?问题:如何获取所有文档id(除了“information”)并在data.table中显示详细信息? List view also acceptable.列表视图也可以接受。
Really appreciate if anyone can help me or provide me some direction.如果有人能帮助我或给我一些指导,我将不胜感激。 Thanks.谢谢。
From what I understand, you want to get all the documents id
s in a collection.据我了解,您想获取集合中的所有documents id
。 To achieve this, you would need a query to get all documents in a collection.为此,您需要一个查询来获取集合中的所有文档。
QuerySnapshot snapshot = await FirebaseFirestore.instance.collection('Society Name').get();
List docs = snapshot.docs;
After you get all the documents, you can now loop the list to get id
from the DocumentSnapshot
.获取所有文档后,您现在可以循环列表以从DocumentSnapshot
获取id
。
docs.forEach((doc){
print(doc.id);
});
For your reference from the official docs:供您参考官方文档:
id → String This document's given ID for this snapshot. id → String 此文档为此快照指定的 ID。 https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/DocumentSnapshot-class.html https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/DocumentSnapshot-class.html
To render as a list widgets you can use ListView.builder
together with FutureBuilder
要呈现为列表小部件,您可以将ListView.builder
与FutureBuilder
一起使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.