I have a StreamBuilder that is connected to Firestore. It supplies a stream of type List<GameResults>
. GameResults is a class that has a key called competitors, which is an array of Competitor objects, each of which has a key called competitorId, which is what I'd like to use to filter. When I call GameResults.fromMap in the gameStream below, I am assuming the resulting stream contains objects that I can use dot notation to access the object properties. When I try to filter the stream based on a specific value (a userId) inside the competitors array, I get an error that says: type '(dynamic) => dynamic' is not a subtype of type '(GameResults) => bool'. Can anyone help me understand where I'm going wrong?
@override
Widget build(BuildContext context) {
final Topic topic = widget.topic;
final firestore = Firestore.instance;
Stream<List<GameResults>> gameStream = firestore
.collection('gameResults')
.where('topicId', isEqualTo: topic.topicId)
.snapshots()
.map((snapshot) {
return snapshot.documents.map((doc) {
return GameResults.fromMap(doc.data);
}).toList();
});
return StreamBuilder(
stream: gameStream,
builder: (context, snapshot) {
final games = snapshot.data;
//below is the offending code:
final myGame = games
.where((game) => game.competitors
.where((competitor) => competitor.competitorId == userId))
.toList()[0];
My Firestore data is