0

I am having an issue, I am getting google place information from one Widget, and I am sending that information to another Widget, in the first one, it seems to be working fine, but inside the other widget, the change is not reflected 'till the page is reloaded

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();
          },
        );
      },
    );
  }
}

It calls to PlaceProfile, but inside it, it still has the previous name, I mean, the redux status is changed, it's reflected in the UserCurrentPlace, so, I got new data from Google, but PlaceProfile is not updated with the new information. By the way, the widget that I want to update is inside a section of 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);
}
Joseph Arriaza
  • 12,014
  • 21
  • 44
  • 63
  • Shouldn't there be a storeprovider in the build method ? – Ian Jan 28 '19 at 18:37
  • StoreProvider is in my main dart file, the one that builds the routing. – Joseph Arriaza Jan 28 '19 at 20:49
  • 1
    Use StreamBuilder instead of FutureBuilder. A FutureBuilder expects only one response. After the first response it closes. StreamBuilder keeps listening even after receiving the first response. Check the difference between FutureBuilder and StreamBuilder here https://stackoverflow.com/questions/50844519/flutter-streambuilder-vs-futurebuilder – Berchmans Jan 28 '19 at 21:24
  • I will try with it – Joseph Arriaza Jan 28 '19 at 21:41
  • was this solved? @JosephArriaza ? It would be really helpful to know as I'm facing the same problem now. – Amani Saaduddin Sep 28 '20 at 16:38

0 Answers0