1

我需要修复这个 GitHub 问题,所以我自己对错误进行了一些挖掘。我有点卡住了,但这是我所拥有的:

在 Flutter 1.12 更新后,使用FlutterView的 API 现在已弃用,应使用新的嵌入包。主要是,平台特定的 java/android/kotlin 代码应该通过DartExecutor或通过方法 channels的回调与 Flutter 对话。但是,我找不到有关如何使用 dart 插件添加新按钮调用的信息。

我理解这段代码的方式(也在下面),Flutter 使用的渲染器被一个非常相似的渲染器覆盖,它将处理从游戏手柄的按钮按下的功能添加到原始 Flutter 渲染器的按钮按下处理。但是,这将不再起作用,因为为此所需的原始 FlutterView 自 1.12 以来已弃用,并且是获取viewand{key|touch}ProcessorField对象所必需的。

val view: FlutterView = registrar.view()

fun viewField(name: String): Field {
   val field = FlutterView::class.java.getDeclaredField(name)
   field.isAccessible = true
   return field
}

// Hack: swap in a new AndroidTouchProcessor.
val touchProcessorField = viewField("androidTouchProcessor")
val rendererField = viewField("flutterRenderer")
val renderer = rendererField.get(view) as FlutterRenderer
val touchProcessor = GamepadAndroidTouchProcessor(renderer)
touchProcessorField.set(view, touchProcessor)

// Hack: swap in a new AndroidKeyProcessor.
val keyProcessorField = viewField("androidKeyProcessor")
val keyEventChannelField = viewField("keyEventChannel")
val textInputPluginField = viewField("mTextInputPlugin")
val keyEventChannel = keyEventChannelField.get(view) as KeyEventChannel
val textInputPlugin = textInputPluginField.get(view) as TextInputPlugin
val keyProcessor = GamepadAndroidKeyProcessor(keyEventChannel, textInputPlugin)
keyProcessorField.set(view, keyProcessor)

Flutter 1.12 之后如何实现集成游戏手柄按键?

4

0 回答 0