Closed hallidev closed 4 years ago
This is already possible. You need to save the subscription in a variable like this:
StreamSubscription loginSubscription = eventBus.on<UserLoggedInEvent>().listen((event) {
print(event.user);
});
loginSubscription.cancel();
@marcojakob It would be great to have this mentioned in the documentation. That way, we don't have to look into issues section on GitHub.
@cnayan It's in there already: https://github.com/marcojakob/dart-event-bus#about-dart-streams
I'm using the bloc pattern and register handlers in bloc constructors. When a bloc goes out of scope, I'd like to unregister the handlers in my dispose method. Currently, blocs that fall out of scope keep registering more handlers. This results in "dead" handlers being called.
I've seen this implemented as eventBus.off(handler) in other event bus implementations.
Would it be possible to get this functionality?