Really struggling with the correct way to achieve the following. If I want to make a native call to Android FROM my Flutter app, there are plenty of examples that I can follow. eg: create an EventChannel and then listen for events and respond to requests from within my Android/Kotlin onMessage listener.
However, what I cannot figure out is how to go the other way! I have a native event that is triggering in the background within native Android. When the event occurs, everything works fine and I can print / debug the data, but I cannot figure out the correct way to package this data up and send back up to Flutter to display in the app:
class MainActivity: FlutterActivity() {
....
....
....
fun somethingHappened(firstName: String, lastName: String, eMail: String) {
Log.d("MyApp","An event has occurred...");
// Log message is printing out correctly, but need to
// create Object / Hashmap / data structure and send to Flutter
}
....
....
}
Can anyone tell me the correct pattern / approach to use and ideally a link to a simple example that I can reference?
Thanks, Jab
success(...)or error -error(...)onListen- api.flutter.dev/javadoc/io/flutter/plugin/common/… - that method gives you a sink i mentioned aboveEventChannel.StreamHandler handler = new EventChannel.StreamHandler() { @Override public void onListen(Object o, EventChannel.EventSink eventSink) { } @Override public void onCancel(Object o) { } }; FlutterView fv = getFlutterView(); new EventChannel(fv, "my.event.channel").setStreamHandler(handler);