events_emitter2 1.0.4 events_emitter2: ^1.0.4 copied to clipboard
Type-safe, multi-listenable, dispose safe event handling classes
example/events_emitter2_example.dart
import 'package:events_emitter2/src/events_emitter.dart';
abstract class CalculationEvent {}
class CalculationResults extends CalculationEvent {
final num results;
CalculationResults({required this.results});
}
class Calculator with EventsEmittable<CalculationEvent> {
void add(num a, num b) {
events.emit(CalculationResults(results: a + b));
}
}
void main(List<String> args) {
var calculator = Calculator();
var listener = calculator.createListener();
listener
.on<CalculationResults>((event) => print("Got results ${event.results}"));
calculator.add(1, 2);
listener.dispose();
}