off method

void off(
  1. Listener<T>? listener
)

Remove event listener from emitter. This will unsubscribe the caller from the emitter from any future events. Listener should be a valid instance. listener - Listener instance to be removed from the event subscription.

Implementation

void off(Listener<T>? listener) {
  if (null == listener) {
    throw ArgumentError.notNull('listener');
  }

  // Check if the listner has a valid callback for cancelling the subscription.
  // Use the callback to cancel the subscription.
  if (false == listener.cancel()) {
    // Assuming that subscription was not cancelled, could be that the cancel callback was not registered.
    // Follow the old trained method to remove the subrscription .
    _removeListener(listener);
  }
}