google_maps_webservice
google_maps_webservice copied to clipboard
Issue with "getDetailsByPlaceId" method
Hello, i want to implement autocomplete, but for my application i need some aditional info about autocomplete result. For this purpose i'm using getDetailsByPlaceId
. Here is the code:
final response = await places.autocomplete(text, language: Get.locale?.languageCode ?? 'en');
predictionsResponse = [];
response.predictions.forEach((e) async {
if (e.placeId != null) {
try {
final details = await places.getDetailsByPlaceId(e.placeId!,
fields: ['address_components', 'name', 'geometry'],
language: Get.locale?.languageCode ?? 'en');
setState(() {
// logger.i(details);
predictionsResponse!.add(
PlaceInfoDetails(
name: details.result.name,
address: details.result.addressComponents
.map((el) => el.shortName)
.join(', '),
location: details.result.geometry!.location,
),
);
});
} catch (error) {
logger.e(error);
}
}
But i'm always getting an error:
E/flutter (13322): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast
E/flutter (13322): #0 _$PlaceDetailsFromJson (package:google_maps_webservice/src/places.g.dart:138:31)
E/flutter (13322): #1 new PlaceDetails.fromJson (package:google_maps_webservice/src/places.dart:710:7)
E/flutter (13322): #2 _$PlacesDetailsResponseFromJson (package:google_maps_webservice/src/places.g.dart:294:26)
E/flutter (13322): #3 new PlacesDetailsResponse.fromJson (package:google_maps_webservice/src/places.dart:838:7)
E/flutter (13322): #4 GoogleMapsPlaces._decodeDetailsResponse (package:google_maps_webservice/src/places.dart:528:29)
E/flutter (13322): #5 GoogleMapsPlaces.getDetailsByPlaceId (package:google_maps_webservice/src/places.dart:126:12)
E/flutter (13322): <asynchronous suspension>
E/flutter (13322): #6 _AddressSearchState._search.<anonymous closure> (package:baby_transfer/widgets/address_search.dart:45:25)
E/flutter (13322): <asynchronous suspension>
It leads me to this line in places.g.dart
file:
...
PlaceDetails _$PlaceDetailsFromJson(Map<String, dynamic> json) {
return PlaceDetails(
adrAddress: json['adr_address'] as String?,
name: json['name'] as String,
>>> placeId: json['place_id'] as String, <<<
...
Does anyone know what does it mean? Or how it can be fixed? Thanks.
Oh, i found the PR, that fixes this issue #126 :)
Hello sir, facing unhandle exception,
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'Map<String, dynamic>' in type cast
E/flutter (25369): #0 _$PlacesDetailsResponseFromJson (package:google_maps_webservice/src/places.g.dart:294:50)
E/flutter (25369): #1 new PlacesDetailsResponse.fromJson (package:google_maps_webservice/src/places.dart:838:7)
E/flutter (25369): #2 GoogleMapsPlaces._decodeDetailsResponse (package:google_maps_webservice/src/places.dart:528:29)
E/flutter (25369): #3 GoogleMapsPlaces.getDetailsByPlaceId (package:google_maps_webservice/src/places.dart:126:12)
E/flutter (25369):
PlacesDetailsResponse _$PlacesDetailsResponseFromJson(
Map<String, dynamic> json) {
return PlacesDetailsResponse(
status: json['status'] as String,
errorMessage: json['error_message'] as String?,
result: PlaceDetails.fromJson(json['result'] as Map<String, dynamic>),
htmlAttributions: (json['html_attributions'] as List
it leads me to this line
- result: PlaceDetails.fromJson(json['result'] as Map<String, dynamic>),*
Dear Lejard
We have a request , can you please fix this issue
fields: ['name'], => this "fields" attribute keeps failing, leading to a huge bill of unwanted attributes
Request you to fix this issue
PlacesDetailsResponse detail =
await _places.getDetailsByPlaceId(
p.placeId.toString(),
fields: ['name'],
language: 'fr',
region:"fr",
);
E/flutter ( 9854): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast
E/flutter ( 9854): #0 _$PlaceDetailsFromJson (package:google_maps_webservice/src/places.g.dart:138:31)
E/flutter ( 9854): #1 new PlaceDetails.fromJson (package:google_maps_webservice/src/places.dart:710:7)
E/flutter ( 9854): #2 _$PlacesDetailsResponseFromJson (package:google_maps_webservice/src/places.g.dart:294:26)
E/flutter ( 9854): #3 new PlacesDetailsResponse.fromJson (package:google_maps_webservice/src/places.dart:838:7)
E/flutter ( 9854): #4 GoogleMapsPlaces._decodeDetailsResponse (package:google_maps_webservice/src/places.dart:528:29)
E/flutter ( 9854): #5 GoogleMapsPlaces.getDetailsByPlaceId (package:google_maps_webservice/src/places.dart:126:12)
E/flutter ( 9854):
was using flutter plugin
Oh, i found the PR, that fixes this issue #126 :)
How did you get the fix? we are using flutter and google_web_service ^0.0.19, we still have the issue and this is latest version(2 yrs back) available on pub.dev
Can you help us how to fix it
fields: ['name'], => this "fields" attribute keeps failing, leading to a huge bill of unwanted attributes fields: ['name'] - this should fetch on name property, so when we use as below, we hit the null problem
-------Snip---------- PlacesDetailsResponse detail = await _places.getDetailsByPlaceId( p.placeId.toString(), fields: ['name'], language: 'fr', region:"fr", );
-------Snip----------
E/flutter ( 9854): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast
E/flutter ( 9854): #0 _$PlaceDetailsFromJson (package:google_maps_webservice/src/places.g.dart:138:31)
E/flutter ( 9854): #1 new PlaceDetails.fromJson (package:google_maps_webservice/src/places.dart:710:7)
E/flutter ( 9854): #2 _$PlacesDetailsResponseFromJson (package:google_maps_webservice/src/places.g.dart:294:26)
E/flutter ( 9854): #3 new PlacesDetailsResponse.fromJson (package:google_maps_webservice/src/places.dart:838:7)
E/flutter ( 9854): #4 GoogleMapsPlaces._decodeDetailsResponse (package:google_maps_webservice/src/places.dart:528:29)
E/flutter ( 9854): #5 GoogleMapsPlaces.getDetailsByPlaceId (package:google_maps_webservice/src/places.dart:126:12)
E/flutter ( 9854):