I'm a noob with flutter, trying to work with some examples. I created a widget that uses a StreamBuilder to pull some query from Firebase. It works great, but it never updates the UI when the data changes. I tried reading about it and from all I can see this should work out of the box. Is there some step I'm missing on the Firebase side to enable the changes to be pushed? Or does the SteamBuilder somehow needs to be configured so it pulls for data every once in a while? The code is basic, just copy and paste from some examples:
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: Firestore.instance
.collection("XXX").orderBy('YYY')
.where("userID", isEqualTo: userID)
.snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
Color.fromRGBO(212, 20, 15, 1.0),
),
),
);
} else {
// Return some list view using the data in snapshot.data.documents
}
}
);
}
[Update]: seems like my data is not updated even when I change the query. I guess it's using some locally cached data and is not fetching it again from the server.
[Update 2]: when I use a query that resolves to no results (e.g. non-existing collection) the spinning wheel just keeps going. When running again the correct query it goes back to the same old results, not reflecting any changes in the Firebase cloud.
[Update 3]: the problem seems to do with my stream containing orderBy. As soon as I remove that everything works fine. Is that a bug??