Reputation: 403
I have created a Collection with 6 fields and the collection has 4 documents with unique UID. I'm able to fetch the data and display it with List view.
I tried using document snapshot, when i print $docSnapshot all i get is Instance of Document snapshot. Am i missing something? I want to fetch the UID and data of each document in the collection.
Stream<DocumentSnapshot> petData = FirebaseFirestore.instance.collection('Data').doc().snapshots();
Widget build(BuildContext context) {
return StreamBuilder<DocumentSnapshot>(
stream: petData,
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot)
{
DocumentSnapshot docSnapshot = snapshot.data;
}
)
}
Upvotes: 0
Views: 247
Reputation: 1411
DocumentSnapshot has a method data()
that retrieves all fields in the document as a Map.
Try adding this line in your builder to check if it works:
print(snapshot.data.data())
Upvotes: 1