EventBus class

自定义事件总线

相当于iOS的NotificationCenter,用于发送事件通知和监听事件通知

使用示例:

EventBus().send(ThemeChangedEvent('follow system : darkTheme'));

订阅事件:

//发送事件
StreamSubscription<ThemeChangedEvent>? _subscription;

_subscription = EventBus().on<ThemeChangedEvent>().listen((event) {
  // 处理事件
  print('Received theme change event: ${event.theme}');
});
//取消订阅
_subscription.cancel();

Constructors

EventBus()
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() → void
关闭所有 StreamController
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
on<T>() Stream<T>
订阅事件
send<T>(T event) → void
发送通知事件
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited