Here's my database (screenshot)
So I can display all books to the user in a pretty standard way using listview:
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection('books').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting: return new Text('Loading...');
default:
return new ListView(
children: snapshot.data.documents.map((DocumentSnapshot document) {
return new ListTile(
title: new Text(document['text']),
subtitle: // I want to display the author's name
);
}).toList(),
);
}
},
);
But the problem is, document['author']
is a DocumentReference
, which I can get by DocumentSnapshot ds = await documentSnapshot['author'].get()
. But the problem is, this is a future which I cannot use inside the ListView. What is the best way to go about this? Use a Futurebuilder for each document snapshot? I also have multiple document references for each book in my actual project