Skip to content

feat: Add vendorId and productId to Gamepads.list() - #135

Open
jpjonte wants to merge 5 commits into
flame-engine:mainfrom
jpjonte:feat/list-vendor-product-ids
Open

feat: Add vendorId and productId to Gamepads.list()#135
jpjonte wants to merge 5 commits into
flame-engine:mainfrom
jpjonte:feat/list-vendor-product-ids

Conversation

@jpjonte

@jpjonte jpjonte commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Problem

Gamepads.list() returns a GamepadController with an id and a name, but no
stable way to recognize a specific physical gamepad.
GamepadEvent already carries vendorId and productId, so those ids only
become available on the first input event.

name could be used, but it's platform-dependent and not guaranteed to be
stable.

The ids are already available natively: gamepad.vendor_id on Linux,
gamepad->vendor_id on Windows, device.vendorId on Android.

Change

  • GamepadController gains vendorId and productId, both int?, read in
    GamepadController.parse the same way GamepadEvent.parse already reads
    them.
  • Each native listGamepads handler now includes vendorId/productId in
    the map it returns.
  • macOS and iOS are untouched: GCController does not expose a vendor/product
    id. vendorId/productId are null there, exactly as GamepadEvent.
  • Added two tests in packages/gamepads/test/gamepads_test.dart:
    GamepadController.parse reads both ids when present, and leaves them
    null when the keys are absent.
  • Documented the new fields in GamepadController's doc comments and added
    a short note to the README's "Getting Started" section.
  • The example app's gamepad list now shows the ids when they're available,
    rendering id - name (054c:0ce6).

Verification

  • dart analyze packages/gamepads_platform_interface packages/gamepads_web packages/gamepads: clean, no issues.
  • flutter test in packages/gamepads: all 82 tests pass, including the two
    new ones.
  • dart format applied to all changed Dart files.
  • Built a throwaway Flutter app with a main.dart that calls
    Gamepads.list() and reads vendorId/productId off the result:
    • flutter build web: succeeded.
    • flutter build apk --debug: succeeded.

Related Issues

Closes #134.

GamepadEvent already carries both, sourced from the native side, but
GamepadController.list() only ever returned id and name. This makes
it possible to identify a connected gamepad before it sends any
input.

Null on macOS and iOS, where GCController does not expose vendor or
product ids.
InputDevice already exposes both; EventListener was already sending
them on every input event.
GamepadInfo already carries both; emit_gamepad_event was already
sending them on every input event.
GamepadData already carries both; emit_gamepad_event was already
sending them on every input event.
Moves the id-parsing helper out of gamepads_web.dart and into
gamepad_detector.dart so getGamepads() can populate vendorId and
productId on the GamepadControllers it constructs, in addition to
the events that already carried them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Report vendorId and productId from Gamepads.list()

1 participant