Objective: Native page initiative to pass information to the Flutter page
Step 1 flutter
Defined EventChannel
static const the EventChannel the EventChannel EventChannel = ( "sample.flutter.io/test_event_channel"); // the Samples may be replaced with the actual package name. To keep the corresponding native.
InitState override methods, monitoring information transfer
@override void initState(){ super.initState(); eventChannel.receiveBroadcastStream().listen(_onEnvent,onError: _onError); } // receiving the passed parameter activity obj void _onEnvent (Object obj) { setState(() { }); } void _onError(Object obj){ }
2 original page
Creating EventChannel , by setSreamHandler in the EventSink pass information to flutter
new EventChannel((FlutterView) flutterView,"Event_Channel").setStreamHandler(new EventChannel.StreamHandler() { @Override public void onListen(Object o, EventChannel.EventSink eventSink) { eventSink.success("hello world !"); } @Override public void onCancel (Object o) { } });