简体   繁体   中英

Flutter Google Places in custom TextField

How would you use a Dart package like Flutter_Google_Places or Google_Places_Picker in your own custom TextFormField ?

Both of these libraries seem to just use Future to await the user picking the place. (example shown below)

    String placeName;        

    var place = await PluginGooglePlacePicker.showAutocomplete(
    mode: PlaceAutocompleteMode.MODE_FULLSCREEN,
    countryCode: country,
    typeFilter: TypeFilter.CITIES);

    placeName = place.name;

Both of these libraries also have two MODES. One for a pre-built pop up search bar and one that is a fullscreen search mode.

在此处输入图片说明

I would like to have this auto search feature but have it use my custom TextFormField.

I was having the same issue with using the flutter_google_places package and I ended up simply using a GET request in the project to directly interact with the Places API.

basically I used a TextEditingController on the TextFormField to listen for when new characters were input, then (after throttling the API request) made the API request and returned the locations as custom card results.

I created a video showing step by step how I did this https://youtu.be/rJOkoAmC5GY

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM