flutter_google_places icon indicating copy to clipboard operation
flutter_google_places copied to clipboard

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

Open Omar-Salem opened this issue 3 years ago • 7 comments

Null check operator used on a null value

Omar-Salem avatar Feb 24 '22 10:02 Omar-Salem

please fix this issue

ziagit avatar Feb 27 '22 11:02 ziagit

same issue

Hosam11 avatar Mar 15 '22 19:03 Hosam11

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

juliansteenbakker avatar Mar 15 '22 20:03 juliansteenbakker

That worked for me. Thanks!

  flutter_google_places:
    git:
        url: https://github.com/fluttercommunity/flutter_google_places
        ref: v0.3.2

sami79031 avatar Mar 24 '22 14:03 sami79031

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)

fefeswa avatar Feb 20 '23 12:02 fefeswa

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.

tariqali786 avatar Aug 03 '23 07:08 tariqali786

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.

andrewpurves8 avatar Feb 21 '24 17:02 andrewpurves8