我在管理流生成器时迷失了方向……请帮忙!
我有一个很棒的类,它从 firestore 获取数据并将其呈现为列表。流包含一个变量 ( rag
),它可以根据用户交互进行更改,我希望流在此类变量更改时更新。我无法让它工作,我相信我的问题是我无法刷新流。如何刷新我的流?在 iOS 中有一个简单的 reloadData 行...
请参阅下面我的代码
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,
);
}
},
);
}
}