简体   繁体   中英

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. 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").

Details: File Title, Submission Date, User Id, Url... Firestore

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

预期产出

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.

Problem: How can I get the all document id (except "information") and show the details in 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. 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 .

docs.forEach((doc){
    print(doc.id);
});

For your reference from the official docs:

id → String This document's given ID for this snapshot. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM