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

Dispose order is wrong #802

Open
ikbendewilliam opened this issue Feb 7, 2023 · 0 comments
Open

Dispose order is wrong #802

ikbendewilliam opened this issue Feb 7, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@ikbendewilliam
Copy link

Describe the bug
The order of the dispose method is wrong.
Now, it first disposes the object and afterwards tries to remove the listeners, which doesn't make sense since it is already disposed. A package I use also throws an error if you execute code after disposing, which does make sense.

Flutter specification on state dispose is relevant here: Implementations of this method should end with a call to the inherited method, as in super.dispose().
I would strongly recommend adding this to the documentation and handling it the same.

In short this:

  @override
  void dispose() {
    super.dispose();
    _removeListener?.call();
    if (_didInitValue) {
      delegate.dispose?.call(element!, _value as T);
    }
  }

should become this:

  @override
  void dispose() {
    _removeListener?.call();
    if (_didInitValue) {
      delegate.dispose?.call(element!, _value as T);
    }
    super.dispose();
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants