eventChannelPlugin的receiveBroadcastStream方法的参数是什么含义
来源:11-10 Flutter与Native通信-Android端实战【实战应用】
小葱与奥特曼
2020-07-16
_streamSubscription = _eventChannelPlugin.receiveBroadcastStream(‘123’).listen(_onToDart, onError: _onToDartError);
这个eventChannelPlugin的receiveBroadcastStream方法的参数是什么含义?
写回答
1回答
-
CrazyCodeBoy
2020-07-20
Stream<dynamic> receiveBroadcastStream([ dynamic arguments ]) { final MethodChannel methodChannel = MethodChannel(name, codec); StreamController<dynamic> controller; ...
这个arguments参数是Dart侧在注册这个广播监听时传递给Native侧的数据。
对应的Native侧的arguments:
new EventChannel(getFlutterView(), CHARGING_CHANNEL).setStreamHandler( new StreamHandler() { private BroadcastReceiver chargingStateChangeReceiver; @Override public void onListen(Object arguments, EventSink events) { chargingStateChangeReceiver = createChargingStateChangeReceiver(events); registerReceiver( chargingStateChangeReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); } @Override public void onCancel(Object arguments) { unregisterReceiver(chargingStateChangeReceiver); chargingStateChangeReceiver = null; } } );
112020-08-08
相似问题