https://github.com/waseemdev/dart-eventhandler
https://github.com/waseemdev/dart-eventhandler
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/waseemdev/dart-eventhandler
- Owner: waseemdev
- License: mit
- Created: 2024-03-27T07:55:30.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-02T12:29:30.000Z (about 2 years ago)
- Last Synced: 2024-04-02T13:44:47.200Z (about 2 years ago)
- Language: Dart
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```dart
class CustomEvent extends EventBase {}
```
### Create a method that receives the custom event type
```dart
void _onCustomEventCallback(CustomEvent event) {
print("CustomEvent received");
}
```
### Subscribe to the event
```dart
@override
void initState() {
EventHandler()
.subscribe(_onCustomEventCallback);
super.initState();
}
```
### Send event
```dart
RaisedButton(
onPressed: () =>
EventHandler().send(CustomEvent())
)
```
### Remember unsubscribe to the event
```dart
@override
void dispose() {
EventHandler()
.unsubscribe(_decreaseCounter);
super.dispose();
}
```
## License
This library is licensed under MIT.