An EventBus follows the publish/subscribe pattern. It allows listeners to subscribe for events and publishers to fire events. This enables objects to interact without requiring to explicitly define listeners and keeping track of them.
This EventBus is perfect for decoupling different layers from each other. Besides the standard functionality provided by EventBus, it appends small additional features that we are using in our products.
import 'package:event_taxi/event_taxi.dart';
// new instance
EventTaxi eventTaxi = EventTaxiImpl();
// singleton instance if preferred
EventTaxi eventTaxi = EventTaxiImpl.singleton();
Note: The EventTaxi is always a singleton
Every event has to be a sub class of Event
.
Those classes can hold additional information if needed.
class RefreshDataEvent implements Event {
// additional information
final DateTime requestTime;
final String fetchedJson;
}
Simply call register
to get a stream of events.
true
will create a stream that immediately emits the last event as well.
(Similar to a BehaviourSubject in RxDart.)
eventBus.registerTo<RefreshDataEvent>(true).listen((event) {
// handle event
});
Create an instance of your Event class and use fire
.
var event = RefreshDataEvent();
eventBus.fire(event);
The Apache License Version 2.0 (Check the LICENCE file in this repository)
Please file feature requests and bugs at the issue tracker.