once<T extends VyuhEvent> method
Subscribe to a single occurrence of an event of type T
.
The listener
will be called only once when an event of type T
is emitted, then the subscription will be automatically cancelled.
Example:
vyuh.event.once<AppStartEvent>((event) {
print('App started at ${event.timestamp}');
});
Implementation
@override
void once<T extends VyuhEvent>(VyuhEventListener<T> listener) {
late final StreamSubscription<T> subscription;
subscription = _eventBus!.on<T>().listen((event) {
listener(event);
subscription.cancel();
});
}