Shrutimahajan / Google-AutoComplete-TextField-Flutter

MIT License
33 stars 111 forks source link

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

Open xcarol opened 8 months ago

xcarol commented 8 months ago

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 _placedetails.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!