fysoul17 / google_maps_place_picker

Place picker on Google Maps for Flutter
MIT License
223 stars 364 forks source link

Custom picked place rebuild the map #8

Closed jcsena closed 4 years ago

jcsena commented 4 years ago

When you add the "selectedPlaceWidgetBuilder" and search using the search bar, selecting a location will reset the map. It only works well if the position is selected using the marker pin.

...
          useCurrentLocation: true,
          usePlaceDetailSearch: true,
          selectInitialPosition: false,
          selectedPlaceWidgetBuilder:
              (_, selectedPlace, state, isSearchBarFocused) {
            return isSearchBarFocused
                ? Container()
                // Use FloatingCard or just create your own Widget.
                : FloatingCard(
                    bottomPosition: MediaQuery.of(context).size.height * 0.05,
                    leftPosition: MediaQuery.of(context).size.width * 0.05,
                    width: MediaQuery.of(context).size.width * 0.9,
                    borderRadius: BorderRadius.circular(12.0),
                    child: state == SearchingState.Searching
                        ? Center(child: CircularProgressIndicator())
                        : RaisedButton(
                            onPressed: () {
                              print("do something with [selectedPlace] data");
                            },
                          ),
                  );
          },
...
fysoul17 commented 4 years ago

That is because of MediaQuery. As you might already guess, the keyboard cause the MediaQuery to rebuild the whole widget. I removed it from the example to avoid confusion.

By Flutter document,

Querying the current media using MediaQuery.of will cause your widget to rebuild automatically > whenever the MediaQueryData changes (e.g., if the user rotates their device).

I am not sure if setting resizeToAvoidBottomInset to false will prevent this, but it is worth trying. I just updated the new version (0.6.4) so that you can handle 'resizeToAvoidBottomInset' property.

If it doesn't work, you must put MediaQuery.of(context) somewhere else or use another method to calculate screen size. (eg. Renderbox)

jcsena commented 4 years ago

I confirm that in the new version(0.6.4) it works