broadcast method

void broadcast(
  1. String key, {
  2. dynamic value,
  3. ValueCallback? callback,
  4. bool persistence = false,
})

广播一条 key 类型的消息。 已经注册在系统中的接收者将会接收到本条消息。 接收者通过 value 可以获取到本条消息携带的数据。 key - 消息类型 value - 消息携带的数据。可以是任意类型或是null。 callback - 能够收到接收器返回的消息 persistence - 是否持久化消息类型。持久化的消息可以在任意时刻通过 FBroadcast.value 获取当前消息的数据包。默认情况下,未持久化的消息类型在没有接收者的时候会被移除,而持久化的消息类型则不会。开发者可以通过 clear 函数来移除持久化的消息类型。

Broadcast a message of type key. Recipients already registered in the system will receive this message. The receiver can get the data carried in this message through value. key - Message type value - The data carried in the message. Can be any type or null. callback - Able to receive the message returned by the receiver persistence - Whether or not to persist message types. Persistent messages can be retrieved at any time by FBroadcast. Value for the current message packet. By default, unpersisted message types are removed without a receiver, while persisted message types are not. Developers can use the clear function to remove persistent message types.

Implementation

void broadcast(String key,
    {dynamic value, ValueCallback? callback, bool persistence = false}) {
  if (_textIsEmpty(key)) return;
  if (persistence && !_get(key).persistence) {
    _get(key).persistence = true;
  }
  _get(key).callback = callback;
  if (value == null || _get(key).value == value) {
    _get(key).notifyListeners();
  } else {
    _get(key).value = value;
  }
}