provider icon indicating copy to clipboard operation
provider copied to clipboard

Dispose order is wrong

Open ikbendewilliam opened this issue 1 year ago • 0 comments

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();
  }

ikbendewilliam avatar Feb 07 '23 10:02 ikbendewilliam