EventBusUtils class
事件总线工具:单例,封装 event_bus 并管理订阅生命周期。
example:
class LoginEvent extends Event {}
eventBus.fire(LoginEvent());
eventBus.listen<LoginEvent>((e) => print('logged in'));
Constructors
- EventBusUtils()
-
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(
) → Future< void> - 销毁事件总线:取消所有已注册的订阅并关闭控制器。
-
fire<
T extends Event> (T e) → void -
广播事件
e。若控制器已关闭则安全跳过(no-op)。 -
listen<
T extends Event> (void onData(T event), {Function? onError, void onDone()?, bool? cancelOnError}) → StreamSubscription< T> -
订阅指定类型
T的事件。返回的 StreamSubscription 会被自动收集, dispose 时统一取消;调用方也可自行提前 cancel。 -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- eventBus → EventBus
-
当前单例持有的
EventBus流(静态访问点)。no setter