addCleaner method

  1. @useResult
VoidCallback addCleaner(
  1. VoidCallback listener
)

Add a callback to be executed when the state is disposed of.

the return callback must be consumed to remove the callback from the list.

Implementation

@useResult
VoidCallback addCleaner(VoidCallback listener) {
  _cleaners.add(listener);
  return () {
    _cleaners.remove(listener);
  };
}