flutter_eventemitter2 1.0.0 flutter_eventemitter2: ^1.0.0 copied to clipboard
Dependency free publish/subscribe(pub/sub) for dart&flutter.
import 'package:flutter_eventemitter/flutter_eventemitter.dart';
void main() {
const MESSAGE = '___message__';
EventEmitter.subscribe(MESSAGE, (data) {
// will receive 1 and 2
// todo: something
});
EventEmitter.subscribeOnce(MESSAGE, (data) {
// will receive 1
// todo: something
});
EventEmitter.publishSync(MESSAGE, 1);
EventEmitter.publishSync(MESSAGE, 2);
// remove subscriber
EventEmitter.clear(MESSAGE);
subscriber(data) {}
String token = EventEmitter.subscribe(MESSAGE, subscriber);
EventEmitter.unsubscribe(token);
EventEmitter.unsubscribe(subscriber);
}