BroadcastEvent<T> class
BroadcastEvent 实例化广播事件、用于非全局范围内,可销毁场景中使用 例如: 仅在当前页面内有效。
使用示例
创建事件name: deafult => 随机生成唯一ID、single: deafult => false均为可选参数
final countChangeEvent = BroadcastEvent
创建监听 countChangeEvent.addListener((count) { debugPrint('count:$count'); });
发送事件 countChangeEvent.emit(1);
- Inheritance
-
- Object
- BroadcastEventInterface<
T> - BroadcastEvent
Constructors
- BroadcastEvent({String? name, bool single = false})
Properties
- count → int
-
监听者数量no setterinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- name ↔ String
-
latefinalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- single → bool
-
单点广播
default:false默认为多点广播、事件可拥有多个监听者 开启后、该事件将永远只同时存在一个监听者,后者会替代前者final
Methods
-
addListener(
void callback(T? data)) → BroadcastSubscription? -
监听事件override -
dispose(
) → void -
移除事件 -
emit(
T? data) → void -
发送事件override -
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