on<E> method

CancelListenFunc on<E>(
  1. FutureOr<void> then(
    1. E
    ),
  2. {bool filter(
    1. E
    )?}
)

Implementation

CancelListenFunc on<E>(
  FutureOr<void> Function(E) then, {
  bool Function(E)? filter,
}) =>
    listen((event) async {
      // event must be E
      if (event is! E) return;
      // filter must be true (if filter is used)
      if (filter != null && !filter(event)) return;
      // cast to E
      await then(event);
    });