feat: Add vendorId and productId to Gamepads.list() - #135
Open
jpjonte wants to merge 5 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Gamepads.list()returns aGamepadControllerwith an id and a name, but nostable way to recognize a specific physical gamepad.
GamepadEventalready carriesvendorIdandproductId, so those ids onlybecome available on the first input event.
namecould be used, but it's platform-dependent and not guaranteed to bestable.
The ids are already available natively:
gamepad.vendor_idon Linux,gamepad->vendor_idon Windows,device.vendorIdon Android.Change
GamepadControllergainsvendorIdandproductId, bothint?, read inGamepadController.parsethe same wayGamepadEvent.parsealready readsthem.
listGamepadshandler now includesvendorId/productIdinthe map it returns.
GCControllerdoes not expose a vendor/productid.
vendorId/productIdarenullthere, exactly asGamepadEvent.packages/gamepads/test/gamepads_test.dart:GamepadController.parsereads both ids when present, and leaves themnullwhen the keys are absent.GamepadController's doc comments and addeda short note to the README's "Getting Started" section.
rendering
id - name (054c:0ce6).Verification
dart analyze packages/gamepads_platform_interface packages/gamepads_web packages/gamepads: clean, no issues.flutter testinpackages/gamepads: all 82 tests pass, including the twonew ones.
dart formatapplied to all changed Dart files.main.dartthat callsGamepads.list()and readsvendorId/productIdoff the result:flutter build web: succeeded.flutter build apk --debug: succeeded.Related Issues
Closes #134.