fluttercommunity / flutter_google_places

Google Places - Google places autocomplete widgets for flutter. No wrapper, use https://pub.dev/packages/google_maps_webservice. Maintainer: @juliansteenbakker
https://pub.dev/packages/flutter_google_places
Other
303 stars 413 forks source link

bug: error thrown when dialog back button is pressed without entering any text into search bar #191

Open Omar-Salem opened 2 years ago

Omar-Salem commented 2 years ago

Null check operator used on a null value

ziagit commented 2 years ago

please fix this issue

Hosam11 commented 2 years ago

same issue

juliansteenbakker commented 2 years ago

Can you please try the following in pubspec.yaml

  flutter_google_places:
    git:
      url: https://github.com/fluttercommunity/flutter_google_places
      ref: v0.3.2
sami79031 commented 2 years ago

That worked for me. Thanks!

  flutter_google_places:
    git:
        url: https://github.com/fluttercommunity/flutter_google_places
        ref: v0.3.2
fefeswa commented 1 year ago

https://github.com/fluttercommunity/flutter_google_places I copied and pasted the code and it keeps giving me this message

I am a beginner in both formats but I have not found more information thanks I have entered my key if you enter a letter it works perfectly but if you don't enter it, an error appears

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following _CastError was thrown while finalizing the widget tree: Null check operator used on a null value PlacesAutocompleteState.dispose (package:flutter_google_places/src/flutter_google_places.dart:467:14)

tariqali786 commented 1 year ago

In flutter_google_places.dart main class it add listener in initState() Timer? _debounce;

@override void initState() { super.initState(); _queryTextController!.addListener(_onQueryChange); // added listener }

in the listener it initialized the _debounce.

void _onQueryChange() { if (_debounce?.isActive ?? false) _debounce!.cancel(); _debounce = Timer(Duration(milliseconds: widget.debounce), () { if (!_queryBehavior.isClosed) { _queryBehavior.add(_queryTextController!.text); } }); } in dispose method it cancels the _debounce with ! operator . @override void dispose() { super.dispose();

_debounce!.cancel();

}

So when we back button pressed without entering text add listener not called and _debounce is not initialized and on dispose we cancel the debounce with ! operator which throws the error because it is not initialized.

So change the _debounce!.cancel() to _debounce?.cancel() will solve the error.

andrewpurves8 commented 6 months ago

In flutter_google_places.dart main class it add listener in initState() Timer? _debounce;

@OverRide void initState() { super.initState(); _queryTextController!.addListener(_onQueryChange); // added listener }

in the listener it initialized the _debounce.

void _onQueryChange() { if (_debounce?.isActive ?? false) _debounce!.cancel(); _debounce = Timer(Duration(milliseconds: widget.debounce), () { if (!_queryBehavior.isClosed) { _queryBehavior.add(_queryTextController!.text); } }); } in dispose method it cancels the _debounce with ! operator . @OverRide void dispose() { super.dispose();

_debounce!.cancel();

}

So when we back button pressed without entering text add listener not called and _debounce is not initialized and on dispose we cancel the debounce with ! operator which throws the error because it is not initialized.

So change the _debounce!.cancel() to _debounce?.cancel() will solve the error.

I'm having the same issue, and manually changing _debounce!.cancel() to _debounce?.cancel() worked for me too. Would be great to have this included in a release.