srtraj / dropdown_textfield

custom dropdown
MIT License
8 stars 48 forks source link

Error Ticker When Ticker is Show and We Click Back #24

Closed curlylazy closed 3 months ago

curlylazy commented 1 year ago

hello,

i found a bug (maybe), when we click the dropdown, while the dropdown showing data, then click back to the previouse page, and suddenly its triggred an error..

FlutterError (_DropDownTextFieldState#6aa21(tickers: tracking 1 ticker) was disposed with an active Ticker.

image

hope you can help me..

dankhan-helmet commented 7 months ago

I'm getting the same error too. I notice that the AnimationController isn't disposed in the dispose() function of the _DropDownTextFieldState class. If you add a check for whether the ticker is animating, then tell it to stop before explicitly disposing of the AnimationController this seems to fix it for me.

@sharathrajMindstack any chance you've seen this before or can verify this fix? I'm not quite sure how to patch or submit a PR.

@override
  void dispose() {
    if (widget.searchFocusNode == null) _searchFocusNode.dispose();
    if (widget.textFieldFocusNode == null) _textFieldFocusNode.dispose();

    // <---  Add code between these lines
    if (_controller.isAnimating) {
      _controller.stop();
    }
    _controller.dispose();
    // <---  end of new lines

    _cnt.dispose();
    super.dispose();
  }
srtraj commented 3 months ago

Thank you for the fix, @dankhan-helmet. I have included it in the latest release. Sorry for delayed response, @curlylazy . I was bus with other things and couldn't maintain this package. The issue has been fixed in the latest release, dropdown_textfield: ^1.1.0

curlylazy commented 3 months ago

thank you so much for fixing the package.

dankhan-helmet commented 3 months ago

Awesome thanks so much for the fix. Just to note that this update only supports flutter >= v3.22 only, due to MaterialStateProperty -> WidgetStateProperty breaking changes.