I want a Kotlin activity to invoke my Dart code using the methodChannel.invokeMethod
method. I want to get the result which is passed on the Dart side. Can someone please help me in extracting the result from MethodChannel.Result callback? How to exactly write the callback?
This is what I have tried:
methodChannel!!.invokeMethod("foo", "arg", object : Result() {
fun success(o: Any?) {
// this will be called with o = "some string"
}
fun error(s: String?, s1: String?, o: Any?) {}
fun notImplemented() {}
})
It doesn't work, it gives me this error:
Type mismatch: inferred type is but MethodChannel.Result? was expected
How am I supposed to write the callback function in Kotlin?