Tomek Polański
1 min readOct 31, 2018

--

Hey,

usually one would like to send events from Flutter to native, but your case is not uncommon.

You can think of button clicks as for of events, and you would like to send to Flutter stream of those clicks.

The best way to do so is using Event Channels.

Those are pretty nicely described in https://medium.com/@svenasse/flutter-event-channels-89623ce6c017

You need to send an event to Flutter when the button is clicked:

EventChannel(flutterView, STREAM).setStreamHandler(
object : EventChannel.StreamHandler {
override fun onListen(args: Any, events: EventChannel.EventSink) {
button?.setOnClickListener {
events.success("")
}
}

override fun onCancel(args: Any) {
button?.setOnClickListener(null)
}
}
)

On Flutter side you need to register to that events just the way it is described in the medium post from Seamus Venasse that I’ve mentioned above.

Let me know if it works.

Cheers!

--

--

Tomek Polański
Tomek Polański

Written by Tomek Polański

Passionate mobile developer. One thing I like more than learning new things: sharing them

No responses yet