I am getting lost in managing stream builder... please help!
I have this great class which get data from firestore and present it as a List. The stream include a variable (rag) which can change based on user interaction and I would like that the stream updates when such variable changes. I am not able to make it work and I believe that my issue is that I am not able to refresh the stream. How can I refresh my stream?? In iOS there is a simple reloadData line for that...
See below my code
class RestaurantList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: _firestore
.collection('restaurants')
.where('lat', isGreaterThan: appData.currentLatitude - rag)
.where('lat', isLessThan: appData.currentLatitude + rag)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasError) return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(
child: new Text(
'Loading...',
),
);
default:
final restDB = snapshot.data.documents;
for (var rest in restDB) {
final restID = rest.documentID;
final name = rest.data['name'];
final lati = rest.data['lat'];
final longi = rest.data['lon'];
final distance = (appData.currentLatitude - lati) *
(appData.currentLatitude - lati) +
(appData.currentLongitude - longi) *
(appData.currentLongitude - longi);
if (longi < appData.currentLongitude + rag &&
longi > appData.currentLongitude - rag) {
final restaurant = Restaurant(
restID: restID,
name: name,
distance: distance,
lati: lati,
longi: longi,
);
restaurants.add(restaurant);
}
}
return ListView(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
children: restaurants,
);
}
},
);
}
}