I accessed value from a field in FireStore but it's in a form of a list and I need to transform it to a Stream<List<>> to put in a streambuilder. How would I do that? Thanks in advance
Asked
Active
Viewed 1,247 times
1
-
read [creating-streams](https://dart.dev/articles/libraries/creating-streams) – Kahou Jun 02 '22 at 03:19
-
Does this answer your question? [How can I create a stream from an array?](https://stackoverflow.com/questions/27888429/how-can-i-create-a-stream-from-an-array) – Kahou Jun 02 '22 at 03:21
1 Answers
1
Instead of getting the value using get()
on a document reference you can use:
Stream documentStream = FirebaseFirestore.instance.collection('myCollection').doc('ABC123').snapshots();
You can use snapshots directly with your StreamBuilder:
final Stream<QuerySnapshot> _usersStream = FirebaseFirestore.instance.collection('users').snapshots();
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: _usersStream,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
....
}

Robert Sandberg
- 6,832
- 2
- 12
- 30