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
CodePudding user response:
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) {
....
}