I am working on a Flutter application that displays a list of categories with items inside. the data is fetched from firebase.
Database structure:
I want to show data like this and it has to be real time:
- Category 1
- Item 1
- Item 2
- Item 3
- Category 2
- Item from category 2 ..
I tried to use Streambuilder, but this only fetches the categories. Could someone help me or point me in the right direction to also get the list of items as a snapshot for each category? Thanks in advance
A snapshot only contains the field and not the collection. So do I need another Streambuilder with the documentID of each category? This seems like a lot of work and heavy database reads, just to get the collection of an item already fetched.
StreamBuilder(
stream: _db.collection('categories').document(widget.id).collection('categories').orderBy('tag', descending: true).snapshots(),
builder: (context, snapshot) {
if(!snapshot.hasData) {
return Loader();
} else {
List<dynamic> docs = snapshot.data.documents;
docs.forEach((element) {
print(element['title']);
print(element.collection('items')); // Does not exist
});
return Text('test');
}
},

