A notification dispatch mechanism that enables the broadcast of information to registered observers.
Getting Started
notification_center is available through pub.dev.
Add the dependency to your pubspec.yaml:
dependencies:
...
notification_center: ^0.0.2
Usage example
Check the example folder
Subscribe observer
NotificationCenter().subscribe('updateCounter', () {
setState(() {
_counter++;
});
});
or
NotificationCenter().subscribe('updateCounter', _updateCounter);
...
void _updateCounter() {
setState(() {
_counter++;
});
}
Unsubscribe observer
NotificationCenter().unsubscribe('updateCounter');
Post notification
NotificationCenter().notify('updateCounter');
Passing data
NotificationCenter().subscribe('updateCounter', (int value) {
setState(() {
_counter = value;
});
});
NotificationCenter().notify('updateCounter', data: 10);