Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with "getDetailsByPlaceId" method #130

Open
ulullul opened this issue Aug 5, 2021 · 5 comments
Open

Issue with "getDetailsByPlaceId" method #130

ulullul opened this issue Aug 5, 2021 · 5 comments

Comments

@ulullul
Copy link

ulullul commented Aug 5, 2021

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.

@ulullul
Copy link
Author

ulullul commented Aug 5, 2021

Oh, i found the PR, that fixes this issue #126 :)

@wrteam02
Copy link

wrteam02 commented Jan 23, 2023

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?)
?.map((e) => e as String)
.toList() ??
[],
);
}

it leads me to this line

  • result: PlaceDetails.fromJson(json['result'] as Map<String, dynamic>),*

@lepepper
Copy link

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):
E/flutter ( 9854): #6 _LocationPickerInitialState.goToPlace (package:rentl/screens/maps/initialOwnerLocationpicker.dart:149:11)
E/flutter ( 9854):

@lepepper
Copy link

was using flutter plugin

@lepepper
Copy link

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):
E/flutter ( 9854): #6 _LocationPickerInitialState.goToPlace (package:rentl/screens/maps/initialOwnerLocationpicker.dart:149:11)
E/flutter ( 9854):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants