Bernardi23 / search_map_place

This is a Flutter package that uses the Google Maps API to make a TextField that tries to autocomplete places as the user types, with simple smooth animations, making a nice UI and UX.
MIT License
127 stars 97 forks source link

Unhandled Exception: setState() called after dispose() #19

Open tatejones opened 4 years ago

tatejones commented 4 years ago

I am using your widget inside a scaffold that is pushed into fullscreen. Very similar to your advance example, except it is pushed into full screen. When the view is Navigator.pop(context) the following error message appears.

VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: setState() called after dispose(): _SearchMapPlaceWidgetState#6d4c8(lifecycle state: defunct, not mounted, tickers: tracking 0 tickers) This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback. The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree. This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().

When I add the following overload to the setState() the error disappears.

@override void setState(fn) { if(mounted){ super.setState(fn); } }

Another suggestion is to make the search TextField to be autofocus or support the option to control the setting.

autofocus: true

tsepulvedacaroca01 commented 4 years ago

where add the override of setState?

rubensdemelo commented 4 years ago

it is already fixed by https://github.com/Bernardi23/search_map_place/pull/16

rubensdemelo commented 4 years ago
  void customListener() {
    Future.delayed(Duration(milliseconds: 500), () {
      if (!this.mounted)
        return;
      setState(() => _tempInput = _textEditingController.text);
      customListener();
    });
dupiesdupreez commented 4 years ago

This is still a problem.

giorgio79 commented 4 years ago

I am getting it too

lzzy12 commented 4 years ago

The change haven't been merged yet. We probably have to install from git with the patch till a new version rolls out like this:

search_map_place:
     git: https://github.com/lzzy12/search_map_place.git

Hope the maintainer releases a new version soon!

rubensdemelo commented 4 years ago

Hi everyone. Create a new version of this package with some fixes, docs, and static analysis https://github.com/rubensdemelo/search_map_place_v2

giorgio79 commented 4 years ago

@rubensdemelo installed your version, but I am getting the issue there as well... [ +423 ms] E/flutter ( 6640): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: setState() called after dispose(): _SearchMapPlaceWidgetState#bb719(lifecycle state: defunct, not mounted, tickers: tracking 0 tickers)

sudo-ulmas commented 3 years ago

Has anyone found a workaround for this problem?

babakoto commented 3 years ago
  void customListener() {
    Future.delayed(Duration(milliseconds: 500), () {
      if (!this.mounted)
        return;
      setState(() => _tempInput = _textEditingController.text);
      customListener();
    });

thanks rubensdemelo