I need to query additional data for every DocumentSnapshot returned by the StreamBuilder, but I can't return the itemBuilder function asynchronously so that I can use await within it. That commented message.loadUser(); was my attempt to query firestore but didn't do the trick.
StreamBuilder(
stream: Firestore.instance
.collection("messages").snapshots(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
return Center(
child: PlatformProgressIndicator(),
);
default:
return ListView.builder(
reverse: true,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
List rev = snapshot.data.documents.reversed.toList();
ChatMessageModel message = ChatMessageModel.fromSnapshot(rev[index]);
//message.loadUser();
return ChatMessage(message);
},
);
}
},
)
Found a solution, just not sure it's the simpler one. Changed the widget returned by the itemBuilder to Stateful and used a FutureBuilder.