matanshukry / flutter_google_places_sdk

Flutter plugin for google places native sdk
32 stars 68 forks source link

Flutter Web | Places Autocomplete Error | Expected a value of type 'Object', but got one of type 'Null' #18

Closed logic-and-math closed 1 year ago

logic-and-math commented 2 years ago

Hi, and thank you for this package!

I have both places api and maps api enabled. I am on flutter 3.0.3.

After running the following line: final response = await places.findAutocompletePredictions("place"); I get the error in the console. The error is the following:

FlutterGooglePlacesSdk::call error: Expected a value of type 'Object', but got one of type 'Null' Error: Expected a value of type 'Object', but got one of type 'Null' at Object.throw_ [as throw] (http://localhost:39703/dart_sdk.js:5080:11) at Object.castError (http://localhost:39703/dart_sdk.js:5039:15) at Object.cast [as as] (http://localhost:39703/dart_sdk.js:5356:17) at Function.as (http://localhost:39703/dart_sdk.js:6603:31) at Object.callMethod$ [as callMethod] (http://localhost:39703/dart_sdk.js:62331:14) at Object.AutocompleteService$36Ext$124getPlacePredictions [as AutocompleteService$Ext|getPlacePredictions] (http://localhost:39703/packages/google_maps/src/generated/google_maps_places.js.g.dart.lib.js:782:107) at flutter_google_places_sdk_web.FlutterGooglePlacesSdkWebPlugin.new.findAutocompletePredictions (http://localhost:39703/packages/flutter_google_places_sdk_web/flutter_google_places_sdk_web.dart.lib.js:337:94) at findAutocompletePredictions.next () at http://localhost:39703/dart_sdk.js:40641:33 at _RootZone.runUnary (http://localhost:39703/dart_sdk.js:40511:59) at _FutureListener.thenAwait.handleValue (http://localhost:39703/dart_sdk.js:35438:29) at handleValueCallback (http://localhost:39703/dart_sdk.js:35999:49) at Function._propagateToListeners (http://localhost:39703/dart_sdk.js:36037:17) at async._AsyncCallbackEntry.new.callback (http://localhost:39703/dart_sdk.js:35753:27) at Object._microtaskLoop (http://localhost:39703/dart_sdk.js:40778:13) at _startMicrotaskLoop (http://localhost:39703/dart_sdk.js:40784:13) at http://localhost:39703/dart_sdk.js:36261:9

Does anybody know why this is happening and the way to resolve it?

erdnj commented 2 years ago

Hi @logic-and-math, Could you supply a sample code to reproduce this error ?

pikaju commented 1 year ago

I solved (or rather worked around) this issue by setting placeTypeFilter to PlaceTypeFilter.ADDRESS.

matanshukry commented 1 year ago

@pikaju not sure why that happened to you since the method has a default value for PlaceTypeFilter ( PlaceTypeFilter placeTypeFilter = PlaceTypeFilter.ALL ). But closing since there's no reproducible code.

I also tried to reproduce locally by calling findAutocompletePredictions with only the query param, but that worked too.

ducpn2111 commented 8 months ago

I had this issue too on flutter web. Here's my code: final places = FlutterGooglePlacesSdk(googleApiKey); try { final predictions = await places.findAutocompletePredictions( query, placeTypesFilter: [PlaceTypeFilter.ADDRESS], ); print('Result: $predictions'); } catch (e) { print('Error: ${e.toString()}'); }