A clean solution to handling callbacks for custom events as a dart library. Are you tired of maintaining initialisation and dispose api of multiple packages in single method? This package helps you modularise event callbacks, allowing for clean, readable and composable code.
Flivver API promotes:
- testability
- composability
- ability to create custom events
- type safety
See example/example.dart
for a complete example.
- Register a service
EventHandler.I.registerEventService<MyEventService>(
MyEventService(),
);
EventHandler.I.registerEventServiceLazy<MyOtherEventService>(
() => MyOtherEventService(),
);
- Unregister a service
EventHandler.I.unregisterEventService(MyEventService());
// Or
EventHandler.I.unregisterEventService<MyEventService>();
- Unregister all services or reset the singleton
EventHandler.I.reset()
// Or
EventHandler.newInstance();
- Create Event Service
class DependencyInjectionService implements EventService {
@override
void call<Event extends Object>(Event currentEvent) {
if (currentEvent is StartupEvent) {
// initialising non-auth dependencies
} else if (currentEvent is LogInEvent || currentEvent is SignInEvent) {
// initialising auth dependencies
} else if (currentEvent is LogOutEvent) {
// clearing dependencies
}
}
}
Flivver only cares about the type, Events
can be classes or enums.
Events can be anything, every service is associated with a list of events for
which it will be called.
Event services are classes that implement the EventService
.
These services are registered with the EventHandler
against selected events.
It has one call
method that will be called for events that the service was
registered against.