I want to write a code that outputs the document id of each document within a document that is in a collection that the StreamBuilder is subscribed to.
My Firestore structure is this:
- 2020-2021 (Collection)
- MyClass (Document)
- Scores (Collection)
- Quiz 1 (these are the document ids of the documents)
- Quiz 2
- Quiz 3
- Scores (Collection)
- MyClass (Document)
My code might seem complicated but what I'm trying to achieve in a nutshell, is to output the document ids of all documents in a collection (Scores) into a list, while the StreamBuilder is subscribed to the changes of the document collecting (MyClass) the collection. However, it gives me this error: NoSuchMethodError: 'doc', method not found, Receiver: null, Arguments:[] I think I'm having a syntax error, but I have no idea how to correct it. I'm also not sure whether the use of the map method is correct.
classname = "MyClass";
CollectionReference schoolYear =
FirebaseFirestore.instance.collection("2020-2021");
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(30),
child: StreamBuilder(
builder: (context, streamSnapshot) {
return SingleChildScrollView(
child: DataTable(
columns: streamSnapshot.data.doc.map((DocumentSnapshot document) {
return new DataColumn(label: Text(document.id));
}).toList(),
rows: <DataRow>[],
),
);
},
stream: schoolYear.doc(classname).snapshots(),
),
);
}
Here's the full error log (after changing to Thavamani's code):
