_TypeError (type 'List<dynamic>' is not a subtype of type 'PlaceDetails')

﹥>﹥吖頭↗ 提交于 2020-02-06 08:09:21

问题


Help me with this error:

I am trying to get place value/name from displayPrediction() and show it in my textformfield Here is the call from TextFormField

TextFormField(
 decoration: textInputDecoration.copyWith(hintText: 'From'),
  onTap: () async {
   Prediction p = await PlacesAutocomplete.show( context: context, apiKey: kGoogleApiKey);
   displayPrediction(p);
  },
)

I want to save the place back to textformfield.
My 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);
    }
  }

回答1:


Just checkout your google places import dependency. It should be as follow

import 'package:flutter_google_places/flutter_google_places.dart';

Also, checkout you have initialised the _places as

GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: "YOUR_API_KEY");


来源:https://stackoverflow.com/questions/59475091/typeerror-type-listdynamic-is-not-a-subtype-of-type-placedetails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!