PadInput class final

Feeds an InputState from a gamepad.

The keyboard's twin: DesktopInput is the only file that knows what a key is, and this is the only one that knows what a thumb stick is. Below both, the simulation sees actions and an axis — which is what lets the same game run from either without a branch.

Polled, not subscribed

tick is called once per frame, before the loop advances, and everything happens there: edges, magnitudes, the view, and letting go of a pad that has been unplugged. Nothing is driven by a stream, even though the platform offers one, because an event arriving between two steps would mutate the player's intent halfway through a frame — and a fixed-step simulation whose input changes mid-step is the kind of bug that only shows up on somebody else's machine.

Gamepad.connectionChanges is still there for a menu that wants to say a controller appeared; this class does not use it.

Two devices, one action, and who wins

A pad releases only what the pad was holding — never InputState.clear, which would drop keys the keyboard is genuinely still holding. It presses and releases exactly once per control and keeps no count of its own: InputState.release counts holds, so two buttons bound to one action are already handled and a second opinion here would fight it. Where a key and a trigger share an action, a magnitude is authoritative while the trigger is off its rest: a player feathering a trigger and holding W gets the trigger's number, because the trigger is what they are moving. A trigger fully at rest withdraws its number (InputState.clearActionValue) and W means full again. The file is pad_actions.dart and the class is PadInput, which is a mismatch on purpose. The plugin this reads is now called pad_input, and a file of that name importing package:pad_input/pad_input.dart is two different things one line apart: the raw device, and this — the translator that turns its sticks and triggers into a game's own verbs. The class keeps its name because every call site says it; the file gives its up because the package needed it more.

Constructors

PadInput({required InputState state, Gamepad? pad, Bindings? bindings, PadRoutes routes = PadRoutes.walking, Map<PadButton, int>? slotButtons, double pressAt = 0.5, double releaseAt = 0.35})

Properties

bindings → Bindings
What each button does. The same object the keyboard uses, if the game passes it: see addDefaultsTo.
final
hashCode → int
The hash code for this object.
no setterinherited
heldButtons → Iterable<PadButton>
What the pad is holding, for a screen rather than for a simulation.
no setter
isConnected → bool
Whether a pad answered the last tick.
no setter
isSupported → bool
no setter
pad → Gamepad
final
pressAt → double
How far a trigger travels before it counts as pressed, and how far back before it counts as released.
final
releaseAt → double
final
routes ↔ PadRoutes
Where the analogue controls go. Mutable, because a game that drives and walks changes it when the player gets out of the car.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
slotButtons → Map<PadButton, int>
final
state → InputState
final

Methods

applySettings(GameConfig config) → void
Takes the player's numbers out of a config.
drainLook(Vector2 out) → void
Adds the view movement accumulated since the last call, and forgets it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
storeSettings(GameConfig config) → void
Writes the player's numbers back, for a settings panel that changed them.
tick(double dt) → void
Reads the pad and writes what it says into the state.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

dpadSlots → Map<PadButton, int>
The d-pad, clockwise from the top.
final

Static Methods

addDefaultsTo(Bindings bindings) → Bindings
Adds the pad's defaults to an existing table and returns it.
defaultBindings() → Bindings
The pad half of a binding table, as a fresh one each call.
knowsPad(Bindings bindings) → bool
Whether bindings mentions a gamepad at all.