FBroadcast class

FBroadcast 帮助开发者在应用内建立一套高效的广播系统,注册到系统中的接收者,将能接收到任意位置发送的对应类型的消息。 同时,FBroadcast 还支持了粘性广播,这将帮助开发这轻松处理一些复杂的通讯场景。

FBroadcast Help developers build an efficient broadcast system in the application. Receivers registered in the system will be able to receive corresponding types of messages sent anywhere. At the same time, FBroadcast also supports sticky broadcasting, which will help developers easily handle some complex communication scenarios.

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

broadcast(String key, {FBModel? value, ValueChanged<FBModel>? callback, bool persistence = false}) → void
广播一条 key 类型的消息。 已经注册在系统中的接收者将会接收到本条消息。 接收者通过 value 可以获取到本条消息携带的数据。 key - 消息类型 value - 消息携带的数据。可以是任意类型或是null。 callback - 能够收到接收器返回的消息 persistence - 是否持久化消息类型。持久化的消息可以在任意时刻通过 FBroadcast.value 获取当前消息的数据包。默认情况下,未持久化的消息类型在没有接收者的时候会被移除,而持久化的消息类型则不会。开发者可以通过 clear 函数来移除持久化的消息类型。
clear(String key) → void
移除广播系统中的指定 key 类型的所有接收者,以及该类型的粘性广播。 key - 类型
dispose() → void
会移除当前广播系统实例中的所有的数据。
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register(String key, FResultCallback<FBModel> receiver, {BuildContext? context, Map<String, FResultCallback<FBModel>>? more}) FBroadcast
注册指定类型的接收者。 如果传入了 context 环境,该接收者将会被注册到环境中。环境可以是任意类型的对象,例如:页面、类.. 接收者通过 value 可以获取到本条消息携带的数据。 当调用 unregister 时,该接收者即会被清除。 key - 消息类型 receiver - 接收者 context - 环境。不为null,receiver 将会被注册到环境中。 more - 方便一次注册多个接收者
remove(FResultCallback<FBModel> receiver, {String key = '', BuildContext? context}) → void
移除指定的接收者 receiver。 如果指定了 keycontext 将有助于更快的移除指定接收者。 receiver - 接收者 key - 消息类型 context - 环境。
stickyBroadcast(String key, {FBModel? value, ValueChanged<FBModel>? callback, bool persistence = false}) → void
广播一条 key 类型的粘性消息。 如果广播系统中还有没注册该类型的接收者,本条消息将被滞留在系统中。一旦有该类型接收者被注册,本条消息将会被立即发送给接收者。 如果系统中已经注册有该类型的接收者,本条消息将会被立即发送给接收者。 接收者通过 value 可以获取到本条消息携带的数据。 key - 消息类型 value - 消息携带的数据。可以是任意类型或是null。 callback - 能够收到接收器返回的消息 persistence - 是否持久化消息类型。持久化的消息可以在任意时刻通过 FBroadcast.value 获取当前消息的数据包。默认情况下,未持久化的消息类型在没有接收者的时候会被移除,而持久化的消息类型则不会。开发者可以通过 clear 函数来移除持久化的消息类型。
toString() String
A string representation of this object.
inherited
unregister(BuildContext context, {bool async = false}) → void
移除广播系统中,注册到 context 环境内的所有接收者。 例如,在页面关闭时,开发者可以通过 unregister 一次性移除注册到该环境内的所有接收者。 当然,前提时在接收者通过 register 注册的时候,传入 context,将接收者注册到该环境中。 context - 环境。

Operators

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

Static Properties

debug bool
getter/setter pair
systemInstance FBroadcast
系统全局实例
no setter

Static Methods

instance([BuildContext? context]) FBroadcast
获取 FBroadcast 系统实例,已进行注册/广播等操作
printFBroadcastInfo() String
输出 FBroadcast 系统中的驻留广播信息
value(String key) FBModel?
接收者可以通过该函数获取消息中的数据