小编Awe*_*Awe的帖子

FlutterActivity MethodChannel 和 FlutterView

所以我在大约 4 个月前写了一个 Flutter 应用程序。现在我想做一个小改动,但我无法再编译应用程序,因为 GeneratedPluginRegistrant.registerWith(this) 不再起作用,我没有更改 Kotlin 代码,只是 Dart 代码。

在“”,在“GeneratedPluginRegistrant.registerWith()”显示我这个错误:

Type mismatch.    
Required: FlutterEngine!    
Found: MainActivity
Run Code Online (Sandbox Code Playgroud)

主活动类:

import android.os.Bundle
import io.flutter.app.FlutterActivity
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.view.FlutterMain

class MainActivity : FlutterActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    GeneratedPluginRegistrant.registerWith(this) // here is the error: Type mismatch. Required: FlutterEngine! Found: MainActivity

    MethodChannel(flutterView, CHANNEL).setMethodCallHandler { call, result ->
      if (call.method == "helloFromNativeCode") {
        val greetings = helloFromNativeCode()
        result.success(greetings)
      }
    }
  }

  private fun helloFromNativeCode(): String { …
Run Code Online (Sandbox Code Playgroud)

android kotlin flutter

9
推荐指数
3
解决办法
1万
查看次数

标签 统计

android ×1

flutter ×1

kotlin ×1