notification_dispatcher 0.4.0 notification_dispatcher: ^0.4.0 copied to clipboard
Inspired by Apple's NotificationCenter. Passes information around to registered observers.
example/notification_dispatcher_example.dart
import 'package:notification_dispatcher/notification_dispatcher.dart';
class YourClass {
int count = 0;
void init() {
NotificationDispatcher.instance.addObserver(
this,
name: 'observerName',
callback: (_) => count++,
);
}
void dispose() {
NotificationDispatcher.instance.removeObserver(this);
}
}
void main() {
final yourClass = YourClass()..init();
NotificationDispatcher.instance.post(name: 'observerName');
print(yourClass.count); // 1
yourClass.dispose();
}