簡體   English   中英

_TypeError(輸入&#39;列表<dynamic> &#39; 不是類型 &#39;PlaceDetails&#39; 的子類型)

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

幫我解決這個錯誤: 在此處輸入圖片說明

我正在嘗試從displayPrediction()獲取位置值/名稱並將其顯示在我的 textformfield 這是來自 TextFormField 的調用

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

在此處輸入圖片說明 我想把這個地方保存回 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);
    }
  }

只需檢查您的 google 位置導入依賴項即可。 它應該如下

import 'package:flutter_google_places/flutter_google_places.dart';

此外,結帳您已將 _places 初始化為

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

錯誤在於 p.description。 我遇到了同樣的問題。 像這樣使用它:

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

  print(address);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM