[英]Flutter: “No implementation found for method” - for cached flutter engine
I want to call a native method from my flutter app but I have an issue:我想从我的颤振应用程序中调用一个本地方法,但我有一个问题:
No implementation found for method getApplicationDocumentsDirectory on channel my_channel/name
I launch my Flutter app from an existing native Android Application and I want to use some native code from Flutter.我从现有的原生 Android 应用程序启动我的 Flutter 应用程序,我想使用 Flutter 的一些原生代码。
So I use an Flutter engine cache and I register my native method handler but it doesn't work:所以我使用 Flutter 引擎缓存并注册我的本地方法处理程序,但它不起作用:
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
"CHANNEL"
).setMethodCallHandler { call, result ->
when (call.method) {
"myMethod" -> {
doMyNativeCode(call, result)
}
else -> {
result.notImplemented()
}
}
}
}
I call this code from Application.onCreate()
when I create flutter engine and put it into cache.当我创建颤振引擎并将其放入缓存时,我从Application.onCreate()
调用此代码。
But my EventChannel's
(listening events from native on flutter) work well .但是我的EventChannel's
(在 flutter 上监听本地事件)运行良好。
What's wrong with it?它出什么问题了?
Maybe my experience can help you.或许我的经验可以帮到你。
My issue was exception on native side:我的问题是本机方面的异常:
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
"CHANNEL"
).setMethodCallHandler { call, result ->
when (call.method) {
"myMethod" -> {
// THERE WAS EXCEPTION!!!
}
else -> {
result.notImplemented()
}
}
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.