Shrutimahajan / Google-AutoComplete-TextField-Flutter

MIT License
33 stars 111 forks source link

GooglePlaceAutoCompleteTextField: Unhandled Exception with Null check operator #32

Open harSofja opened 1 year ago

harSofja commented 1 year ago

I'm encountering an issue with the GooglePlaceAutoCompleteTextField widget from the google_places_flutter package. Every time I type a location into the search bar and select a suggestion from the auto-suggested list, I receive an error in my console logs.

Error: csharp Copy code [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value

0 _GooglePlaceAutoCompleteTextFieldState.getPlaceDetailsFromPlaceId

google_places_flutter.dart:252

Relevant Code: dart Copy code Future getPlaceDetailsFromPlaceId(Prediction prediction) async { var url = "https://maps.googleapis.com/maps/api/place/details/json?placeid=${prediction.placeId}&key=${widget.googleAPIKey}"; Response response = await Dio().get(url); PlaceDetails placeDetails = PlaceDetails.fromJson(response.data); prediction.lat = placeDetails.result!.geometry!.location!.lat.toString(); prediction.lng = placeDetails.result!.geometry!.location!.lng.toString(); widget.getPlaceDetailWithLatLng!(prediction); } Steps to Reproduce: 1.Type a location into the GooglePlaceAutoCompleteTextField search bar. 2.Select any location from the suggested dropdown. 3.Observe the error in the console logs. Additional Context: The error seems to be related to the getPlaceDetailsFromPlaceId method, specifically when trying to access properties of the placeDetails object. I've ensured that the necessary API keys and configurations are correctly set up. Thank you in advance. Screenshots: ![unhandled exception marked](https://github.com/Shrutimahajan/Google-AutoComplete-TextField-Flutter/assets/123031342/ff88d0e6-8c75-4a0b-bf64-581d8103dbda) ![relevant code](https://github.com/Shrutimahajan/Google-AutoComplete-TextField-Flutter/assets/123031342/bab4498d-5b0c-4ae1-922d-c581d544f0f2)
kyadalu1 commented 1 year ago

https://www.youtube.com/watch?v=3M5fKhc1PJw