问题
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