![](/img/trans.png)
[英]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.