mohesu / map_location_picker

Map location picker for flutter Based on google_maps_flutter
Apache License 2.0
46 stars 68 forks source link

ClearButton disappears after selecting a Suggestion #11

Closed jansvanda closed 1 year ago

jansvanda commented 1 year ago

The clearbutton doesn't stay after I pick a Suggestion. It disappears and If i picked a Suggestion and want to remove it, i only have the option to remove it manually all the text with the keyboard.

Using your latest version 1.0.4

Padding(
                                padding: const EdgeInsets.fromLTRB(15, 10, 15, 5),
                                child: Form(
                                  key: _locationKey,
                                  child: PlacesAutocomplete(
                                    showClearButton: true,
                                  hideSuggestionsOnKeyboardHide: false,
                                    borderRadius : const BorderRadius.all(Radius.circular(4)),
                                    topCardShape: const RoundedRectangleBorder(
                                      borderRadius: BorderRadius.all(Radius.circular(4)),
                                    ),
                                    apiKey: "KEY_G",
                                    searchHintText: "Zadejte adresu ",
                                    mounted: mounted,
                                    showBackButton: false,
                                    language: 'cs',
                                    components: [Component(Component.country, "cz")],
                                    initialValue: initialValue,
                                    onSuggestionSelected: (value) {
                                      setState(() {
                                        autocompletePlace =
                                            value.structuredFormatting?.mainText ?? "";
                                        initialValue = value;
                                      });
                                    },
                                    onGetDetailsByPlaceId: (value) {
                                      setState(() {
                                        address = value?.result?.formattedAddress ?? "";
                                      });
                                    },
                                    validator: (value) {
                                      if (value == null) {
                                        return 'Zadejte prosím adresu';
                                      }
                                      return null;
                                    },
                                  ),
                                ),
                              ),
jansvanda commented 1 year ago

I found in autocomplete_view.dart that on line 218 you wrote

suffixIcon: (showClearButton && initialValue == null)
                    ? IconButton(
                        icon: const Icon(Icons.close),
                        onPressed: () => textController.value.clear(),
                      )
                    : suffixIcon,

But that means if initialvalue gets != null, the suffix icon is shown. But that makes no sense, we want to clear the controller IF there is already something inside!

rvndsngwn commented 1 year ago

Because of assert(initialValue == null || controller == null) in TextFormField

if you assign a controller then no need to assign initialvalue.

rvndsngwn commented 1 year ago

more customizable options added.

jansvanda commented 1 year ago

Hello in #1.1.0 the clearButton still disappears after an suggestion is picked, or am I missing some option?

jansvanda commented 1 year ago

I am very sorry, it was because I still have been using initialValue. After deleting this it shows the clearButton !