I am pulling data from Firestore as a Stream of a List. I want to take all of the values that are held by the stream and add them to a separate list.
// getting the stream
Stream<List<AttractionNode>> readAttractionsNodes() =>
FirebaseFirestore.instance
.collection("attractions")
.where("tags", arrayContainsAny: selectedChips)
.snapshots()
.map((snapshot) => snapshot.docs
.map((doc) => AttractionNode.fromJson(doc.data()))
.toList());
Stream<List<AttractionNode>> _nodes = readAttractionsNodes();
// the list that should hold all nodes from the stream List<AttractionNode> allNodes = [];
_nodes.listen( (listOfNodes) { allNodes = listOfNodes; });
However, it seems that outside of the listen block, allNodes stays empty. How can I fix that?
>`. Instead, you can use `.get()` which returns `Future
– Sahil Sonawane Nov 14 '22 at 10:37>`
>. How can I get that to be just a List?
– rk793 Nov 15 '22 at 21:56