I structured my firestore database as follow:
to display the data in flutter i use streambuilder as follow:
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection('myCollection').snapshots(),
builder: (context, snapshot) {
return Container(
child: ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) =>
_buildListItem(context, snapshot.data.documents[index]),
),
);
}),
Widget _buildListItem(BuildContext context, DocumentSnapshot document) {
return ListTile(
title: Row(
children: <Widget>[
Text(document.documentID),
Spacer(),
Text(document['allocatedSource'].toString()),
],
),
how do I access the subcollection like this: subtitle: Text(document.documentID.collection('post').document).
I can access that if i declare the stream as follow:
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('myCollection')
.document(documentId)
.collection('post')
.snapshots(),...
but then I will lose the access to the documentID from the collection. Should I declare 2 stream or nest the streambuilder?
