flutter_gamepad 0.3.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

flutter_gamepad #

A platform library for listening to hardware gamepads (game controllers) from Flutter.

Features #

  • FlutterGamepad.gamepads() returns info about all currently connected gamepads.
  • FlutterGamepad.eventStream reports gamepad events. (See example)
  • Fractional button values, such as those reported by the left and right trigger buttons on most gamepads, are supported.
  • Supports iOS 13+, as well as older versions of iOS.
  • Supports Android.
  • Supports multiple simultaneous gamepads. Events are tagged with an ID you can tell gamepads apart by.

Caveats #

  • On Android, the B button seems to trigger a "back" action. You'll want to have a WillPopScope on your game scaffold to prevent this.
  • On Android, "disconnect" events are never fired. "Connect" events are fired initially when listening to the stream, and thereafter on the first input of any new gamepads. This differs from the iOS behavior, where a "connect" event is sent when the connection is established, even if no buttons have been pressed.

Example #

import 'package:flutter_gamepad/flutter_gamepad.dart';

class _MyWidgetState extends State<MyWidget> {
  StreamSubscription<GamepadEvent> _gamepadEventSubscription;

  void initState() {
    _gamepadEventSubscription = FlutterGamepad.eventStream.listen(onGamepadEvent);

  void dispose() { _gamepadEventSubscription.cancel(); super.dispose(); }

  void onGamepadEvent(GamepadEvent e) {
    if (e is GamepadConnectedEvent) {
      // ...
    } else if (e is GamepadDisconnectedEvent) {
      // ...
    } else if (e is GamepadButtonEvent) {
      // ...
    } else if (e is GamepadThumbstickEvent) {
      // ...
    } else throw ArgumentError('Unknown event: $e');

0.3.1 #

  • Don't create a gamepadState for just any keyUp event

0.3.0 #

  • Fix keyup events

0.2.1 #

  • Add "pressed" key to button events

0.2.0 #

  • Bump Kotlin version

0.1.0 #

Add a gamepads method for retrieving current gamepad info.

0.0.5 #

Remove some stray debugging code.

0.0.4 #

Run flutter format and add a stripped-down example to the library README.

0.0.3 #

Hide some internals and write a README for the example.

0.0.2 #

Write a README.

0.0.1 #

Initial release.

  • Basic implementation for iOS.
  • Events are sent to Flutter over FlutterGamepad.eventStream whenever controllers are connected and disconnected, and whenever their buttons or sticks change state.
  • Supports MFi, and (in iOS 13+) Xbox and DualShock controllers.


flutter_gamepad_example #

Demonstrates how to use the flutter_gamepad plugin.

  • example/lib/main.dart is a self-contained demo on how to subscribe to GamepadEvents and handle them (in this case, showing a log of gamepad events in a widget).

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_gamepad: ^0.3.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_gamepad/flutter_gamepad.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/flutter_gamepad.dart.

Run flutter format to format lib/flutter_gamepad.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies