_TypeError(类型“ List <dynamic>”不是类型“ PlaceDetails”的子类型)

时间:2019-12-25 03:54:03

标签: android google-maps flutter dart google-places-api

请帮助我解决此错误: enter image description here

我正在尝试从displayPrediction()获取位置值/名称并将其显示在我的textformfield中 这是来自TextFormField的呼叫

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

enter image description here 我想将地点保存回textformfield。
我的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);
    }
  }

2 个答案:

答案 0 :(得分:0)

只需签出您的Google Places导入依赖项即可。应该如下

import 'package:flutter_google_places/flutter_google_places.dart';

另外,结帐时您已将_places初始化为

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

答案 1 :(得分:0)

p.description错误。我遇到了同样的问题。 像这样使用它:

List address = [];
  address.add(p.description);

  print(address);