我如何从PlacesAutocomplete的地方中选取值并将其存储在TextFormField中

问题描述 投票:0回答:1

我想使用PlacesAutocomplete获取地点并将其存储在我的TextFormField中。我正在从displayPrediction()]呼叫TextFormFeild()

TextFormField(
                    decoration: textInputDecoration.copyWith(hintText: 'From'),
                    onTap: () async {
                      Prediction p = await PlacesAutocomplete.show( 
                        context: context,
                        apiKey: kGoogleApiKey,
                        mode: Mode.overlay,
                        //language: "en",
                        //components: [Component (Component.country, "en")],
                        );
                      displayPrediction(p);
                    },
                  ),

这里是displayPrediction()

Future<Null> displayPrediction(Prediction p) async {
    if (p != null) {
      PlacesDetailsResponse detail =
      await _places.getDetailsByPlaceId(p.placeId);

      var placeId = p.placeId;
      double lat = detail.result.geometry.location.lat;
      double lng = detail.result.geometry.location.lng;

      var address = await Geocoder.local.findAddressesFromQuery(p.description);

      print(lat);
      print(lng);
      print(address);
    }
  }

变量kGoogleApiKey和_places

const kGoogleApiKey = "My_API_Key";

GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: kGoogleApiKey);

我想在我的TextFormField上轻敲后在那个相同的TextFormField中显示相同的位置]enter image description here

并且选择位置后出现此错误-_TypeError (type 'List<dynamic>' is not a subtype of type 'PlaceDetails')

我想使用PlacesAutocomplete获取地点并将其存储在我的TextFormField中。我从TextFormFeild()TextFormField(装饰:textInputDecoration ....

android flutter dart google-places-api google-places
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.