Notification Center

Pub Version

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

Usage example

Check the example folder

Add a subscribers

NotificationCenter().subscribe('updateCounter', (data) {
  setState(() {
    _counter += data;
  });
});

or

NotificationCenter().subscribe('updateCounter', _updateCounter);

...

void _updateCounter(data) {
  setState(() {
    _counter++;
  });
}

Remove subscribers

NotificationCenter().unsubscribe('updateCounter');

Post notification

NotificationCenter().notify('updateCounter');

Passing data

NotificationCenter().subscribe('updateCounter', (int data) {
  setState(() {
    _counter += data;
  });
});
NotificationCenter().notify('updateCounter', data: 10);

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();

Libraries

notification_center
A simple notification center. A notification dispatch mechanism that enables the broadcast of information to registered observers.