1

I need this GitHub issue fixed, so I did some digging into the error myself. I am kind of stuck but here is what I've got:

After the Flutter 1.12 update, the API using FlutterView is now depracted and instead the new embedding packages should be used. Mainly, platform specific java/android/kotlin code should talk to flutter via the DartExecutor or via callbacks from method channels. However I cannot find information on how to add new button calls with a dart plugin.

The way I understand this code(also below), the renderer Flutter uses is overridden by a very similar one, that adds the functions to handle button presses from the gamepad to the button press-handling of the original flutter renderer. However this won't work anymore beacuse the original FlutterView required for this is deprecated since 1.12 and is required to get the view and {key|touch}ProcessorField objects.

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)

How can integrating gamepad buttons be achieved after Flutter 1.12?

halfer
  • 19,824
  • 17
  • 99
  • 186
jaaq
  • 1,188
  • 11
  • 29

0 Answers0