n_gamepad 0.0.5 n_gamepad: ^0.0.5 copied to clipboard
Flutter plugin for listening to various game controller inputs.
n Gamepad #
A Flutter plugin to listen to game controller inputs.
Features #
- Allows listening to controller inputs from gamepad accessories on Android phones
- Provides a framework to implement multi-device functionality, as demonstrated in this video
Getting started #
Add the following lines of code to your FlutterActivity
in order to override Android's standard input settings for gamepads:
class MainActivity : FlutterActivity() {
private lateinit var view: View
override fun onStart() {
super.onStart()
view = window.findViewById<ViewGroup>(FLUTTER_VIEW_ID).getChildAt(0)
}
override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
return view.dispatchKeyEvent(event)
}
}
This configuration step is necessary for the proper functioning of the plugin on the Android platform.
Usage #
Access the Gamepad.instance
and assign handlers to a specific Button
, the dpad, joysticks, and triggers. To reset individual input handlers, call the same method without specifying any functions.
// Sets onPress and onRelease handler for the A button
Gamepad.instance.assignButtonListener(Button.a, onPress: (event) {}, onRelease: (event) {});
// Resets onPress and sets onRelease handler for the B button
Gamepad.instance.assignButtonListener(Button.b, onRelease: (event) {});
// Sets onUse handler for the right joystick
Gamepad.instance.assignJoystickListener(Hand.right, onUse: (event) {});
// Resets onPress and onRelease handler of B button
Gamepad.instance.assignButtonListener(Button.b);
// Resets handlers for all input controls
Gamepad.instance.resetControls();
Additional information #
For comprehensive documentation on the network capabilities, please refer to the nx Gamepad repository.