Reputation: 51
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 ...
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.
Upvotes: 0
Views: 1996
Reputation: 1294
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
Upvotes: 1