Flutter_google_places null check operator

Viewed 46

In my Flutter application, I'm trying to implement flutter_google_places

When calling PlacesAutocomplete.show

I get this error:

Null check operator used on a null value" #0
PlacesAutocompleteState.doSearch (package:flutter_google_places/src/flutter_google_places.dart:436:28)

I call it this: kGoogleApiKey is provided as a string.

PlacesAutocomplete.show(
  context: context,
  apiKey: kGoogleApiKey,
  mode: Mode.fullscreen, // Mode.overlay
  language: "en",
  components: [Component(Component.country, "pk")]
).then((value) => print(value))

Using:

flutter_google_places: ^0.3.0
google_maps_webservice: ^0.0.16

In Flutter 3.3.1

1 Answers

According to this github issue, you will need to provide more arguments to your function call. If they are not provided, the function body will still try to access these non-existing values and throw an exception while doing so.

Prediction p = await PlacesAutocomplete.show(
  offset: 0,
  radius: 1000,
  types: [],
  strictbounds: false,
  region: "ar",
  context: context,
  apiKey: kGoogleApiKey,
  mode: Mode.overlay, // Mode.fullscreen
  language: "en",
  components: [Component(Component.country, "pk")]
);
Related