我遇到了一个问题,我正在从一个小部件中获取Google地方信息,并将该信息发送给另一个小部件,在第一个小部件中,它似乎运行良好,但是在另一个小部件中,更改是直到页面重新加载后才反映出来
UserCurrentPlace
class _UserCurrentPlaceState extends State<UserCurrentPlace> {
_UserCurrentPlaceState();
@override
Widget build(BuildContext context) {
return new StoreConnector<ReduxState, UserCurrentPlaceViewModel>(
converter: (store) {
return new UserCurrentPlaceViewModel(
currentUserPlace: store.state.currentUserPlace,
onUserPlaceRatingChanged: (isRatingPlace) =>
store.dispatch(new SetUserPlaceRating(isRatingPlace)),
onCurrentUserPlaceChanged: (currentUserPlace) =>
store.dispatch(new SetCurrentUserPlace(currentUserPlace)));
},
builder: (context, vm) {
return FutureBuilder<GooglePlace>(
future: GooglePlaceAPIHelper.getPlaceInformation(vm.currentUserPlace.placeModel.googleId),
builder: (context, snapshot) {
if (snapshot.hasData) {
return new PlaceProfile(snapshot.data, true);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return Utility.getLoading();
},
);
},
);
}
}
它调用PlaceProfile,但是在其中,它仍然具有以前的名称,我的意思是,redux状态已更改,它反映在UserCurrentPlace中,因此,我从Google获得了新数据,但是PlaceProfile并未使用新的消息。顺便说一下,我要更新的小部件在flutter_gallery的一部分内。
class PlaceProfileState extends State<PlaceProfile> {
PlaceProfileState(this._place, this.isCurrentPlace);
final GooglePlace _place;
bool isCurrentPlace;
@override
Widget build(BuildContext context) {
return Text(_place.name);
}
}
class PlaceProfile extends StatefulWidget {
PlaceProfile(this._place, this.isCurrentPlace);
final GooglePlace _place;
final bool isCurrentPlace;
@override
PlaceProfileState createState() =>
new PlaceProfileState(this._place, this.isCurrentPlace);
}