addAutoDisposeListener method

void addAutoDisposeListener(
  1. Listenable? listenable, [
  2. VoidCallback? listener,
  3. String? id
])

Add a listener to a Listenable object that is automatically removed when cancel is called.

Implementation

void addAutoDisposeListener(
  Listenable? listenable, [
  VoidCallback? listener,
  String? id,
]) {
  if (listenable == null || listener == null) return;
  _listenables.add(listenable);
  _listeners.add(listener);
  listenable.addListener(listener);

  if (id != null) {
    _listenerIdExpando[listener] = id;
  }
}