eventhandler 1.0.4 eventhandler: ^1.0.4 copied to clipboard
Simple event handler with singleton constructor. An event is associated with each type of object that it inherits from EventBase.
EventHandler for dart #
Simple event handler with singleton constructor. An event is associated with each type of object that it inherits from EventBase.
Examples #
Implement custom event #
class CustomEvent extends EventBase {}
Create a method that receives the custom event type #
void _onCustomEventCallback(CustomEvent event) {
print("CustomEvent received");
}
Subscribe to the event #
@override
void initState() {
EventHandler()
.subscribe(_onCustomEventCallback);
super.initState();
}
Send event #
RaisedButton(
onPressed: () =>
EventHandler().send(CustomEvent())
)
Remember unsubscribe to the event #
@override
void dispose() {
EventHandler()
.unsubscribe(_decreaseCounter);
super.dispose();
}
License #
This library is licensed under MIT.