[英]Unhandled Exception: MissingPluginException(No implementation found for method ... on channel ...)
[英]Flutter: Unhandled Exception: MissingPluginException(No implementation found for method on channel)
我想在我的颤振代码中调用一个 kotlin 函数(只是为了使用同意 sdk 设置参数),但是,每次我尝试调用该函数(目前只是测试代码)时,我都会收到错误: Unhandled Exception: MissingPluginException(No implementation found for method getConsent on channel consent.sdk/consent)
这是我的MainActivity.kt
样子:
import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant
import android.os.Bundle
import io.flutter.plugin.common.MethodChannel
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
MethodChannel(flutterView, "consent.sdk/consent").setMethodCallHandler {
// Note: this method is invoked on the main thread.
call, result ->
if (call.method == "getConsent") {
result.success("Yay")
} else {
result.success("Yey")
//result.notImplemented() Commented out to see if this caused the error, but it didn't
}
}
}
}
这就是我尝试在颤振中“运行”这段代码的方式:
const platform = const MethodChannel('consent.sdk/consent');
Future<String> _getConsent() async {
String result;
try {
result = await platform.invokeMethod('getConsent');
} on PlatformException catch (e) {
result = "Failed: '${e.message}'.";
}
return result;
}
我究竟做错了什么?
所以我的问题是通过运行解决的: flutter clean
然后运行应用程序
谢谢dlohani
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.