instance static method

FBroadcast instance([
  1. dynamic context
])

获取 FBroadcast 系统实例,已进行注册/广播等操作

Obtained FBroadcast system instance, registered/broadcast and other operations have been performed

context 作用域环境。通过作用域环境获取到广播系统,其有效范围将会被限制在作用域范围内(即 context 环境中)。 作用域内发送的广播,只能被作用域内注册的接收器所接收。而其它作用域将不受其影响,即使它们使用了相同的 Key。 context 可以是任意类型的对象实例。 通过 FBroadcast.dispose 可以释放一个广播系统。 如果 context 为 null,将返回全局广播。 context Scope environment. The broadcast system is acquired through the scope environment, and its effective scope will be limited within the scope (ie in the context environment). Broadcasts sent within the scope can only be received by receivers registered in the scope. The other scopes will not be affected by it, even if they use the same Key. context can be any type of object instance. A broadcast system can be released through FBroadcast.dispose. If context is null, global broadcast will be returned.

Implementation

static FBroadcast instance([dynamic context]) {
  if (context == null) {
    return _instance;
  } else {
    if (_broadcastMap.containsKey(context) &&
        _broadcastMap[context] != null) {
      return _broadcastMap[context]!;
    } else {
      FBroadcast newObj = FBroadcast._();
      newObj._key = context;
      _broadcastMap[context] = newObj;
      return newObj;
    }
  }
}