Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Omar-Salem opened this issue Feb 24, 2022 · 7 comments

Comments

@Omar-Salem
Copy link

Null check operator used on a null value

@Omar-Salem Omar-Salem changed the title error thrown when dialog back button is pressed without entering any text into search bar bug: error thrown when dialog back button is pressed without entering any text into search bar Feb 24, 2022
@ziagit
Copy link

ziagit commented Feb 27, 2022

please fix this issue

@Hosam11
Copy link

Hosam11 commented Mar 15, 2022

same issue

@juliansteenbakker juliansteenbakker added this to the 0.3.2 milestone Mar 15, 2022
@juliansteenbakker
Copy link
Collaborator

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
Copy link

sami79031 commented Mar 24, 2022

That worked for me. Thanks!

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

@fefeswa
Copy link

fefeswa commented Feb 20, 2023

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
Copy link

tariqali786 commented Aug 3, 2023

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants