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

Unhandled Exception: type 'int' is not a subtype of type 'double?' #44

Open
xcarol opened this issue Feb 6, 2024 · 0 comments
Open

Comments

@xcarol
Copy link

xcarol commented Feb 6, 2024

While searching for "Canada" with placeID: ChIJ2WrMN9MDDUsRpY9Doiq3aJk the following unhandled exception occurs:

E/flutter (29191): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'int' is not a subtype of type 'double?'
E/flutter (29191): #0      new Location.fromJson (package:google_places_flutter/model/place_details.dart:172:5)
E/flutter (29191): #1      new Viewport.fromJson (package:google_places_flutter/model/place_details.dart:192:15)
E/flutter (29191): #2      new Geometry.fromJson (package:google_places_flutter/model/place_details.dart:149:15)
E/flutter (29191): #3      new Result.fromJson (package:google_places_flutter/model/place_details.dart:68:15)
E/flutter (29191): #4      new PlaceDetails.fromJson (package:google_places_flutter/model/place_details.dart:9:38)
E/flutter (29191): #5      _GooglePlaceAutoCompleteTextFieldState.getPlaceDetailsFromPlaceId (package:google_places_flutter/google_places_flutter.dart:254:46)

This is due the lat/lng of the viewport of this place, as they have no decimals, they are treated as int. When getPlaceDetailsFromPlaceId calls the following url:

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJ2WrMN9MDDUsRpY9Doiq3aJk&key=AIzaSyAy3LfcYEWsBbtsmLwXfA5nmW3bBqTY7K4

it fails to parse:

viewport	
    northeast	
        lat	70
        lng	-50
    southwest	
        lat	42
        lng	-142

at place_details.dart line #172:

lat = json['lat'];

it could be fixed with the following change, to this and the following line:

lat = double.parse(json['lat'].toString());
lng = double.parse(json['lng'].toString());

Thanks!

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

1 participant