Last updated:
0 purchases
notification center
Notification Center #
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: ^1.0.2
copied to clipboard
Usage example #
Check the example folder
Add a subscribers
NotificationCenter().subscribe('updateCounter', (data) {
setState(() {
_counter += data;
});
});
copied to clipboard
or
NotificationCenter().subscribe('updateCounter', _updateCounter);
...
void _updateCounter(data) {
setState(() {
_counter++;
});
}
copied to clipboard
Remove subscribers
NotificationCenter().unsubscribe('updateCounter');
copied to clipboard
Post notification
NotificationCenter().notify('updateCounter');
copied to clipboard
Passing data
NotificationCenter().subscribe('updateCounter', (int data) {
setState(() {
_counter += data;
});
});
copied to clipboard
NotificationCenter().notify('updateCounter', data: 10);
copied to clipboard
Pause/resume or cancel the subscription
final subscription = NotificationCenter().subscribe('updateCounter', (int data) {
setState(() {
_counter += data;
});
});
//Do some work...
subscription.pause();
print(subscription.isPaused); // true
subscription.resume();
print(subscription.isPaused); // false
subscription.cancel();
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.