once<E> method
convenience method to listen & filter a specific event type, just once.
Implementation
void once<E>(
FutureOr<void> Function(E) then, {
bool Function(E)? filter,
}) {
CancelListenFunc? cancelFunc;
cancelFunc = 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);
// cancel after 1 event
cancelFunc?.call();
});
}