FocusManager class Focus Input
Manages which InteractableComponentInstance currently has keyboard or mouse focus, and updates focus state in response to user input.
The FocusManager is the bridge between raw input events (keyboard/mouse) and the focus/hover/interaction state of interactive components. It:
- Tracks all registered focusable and hoverable components.
- Moves focus between components when the user presses
Tab
orShift+Tab
. - Updates hover and click state in response to mouse events.
- Notifies components when they gain or lose focus/hover.
- Produces a ResponseInput describing what changed and what needs to be redrawn.
Lifecycle
- Registration — Components must be registered via register each frame before input is handled.
- Handling input — handleInput is called with incoming InputEvents.
- Updating state — The focus manager mutates internal focus/hover state and produces a ResponseInput marking components that should be re-rendered.
- Reset — Call reset when the component tree changes drastically or when the UI is torn down.
Example: External usage
final focusManager = FocusManager(context: appContext);
// During layout or component build:
for (final component in interactableComponents) {
focusManager.register(component);
}
// During event loop:
final response = focusManager.handleInput(event);
if (response.handled) {
// write handling logic here
}
See also:
- InteractableComponentInstance, because it defines
focus
,blur
,hover
,unhover
, andonClick
which FocusManager depends on. - InputHandler, because FocusManager implements it to integrate with the app’s event dispatch system.
- ResponseInput, because it’s the structured result you use to decide what to re-render after focus changes.
- Implemented types
Constructors
- FocusManager.new({required Context context})
-
Creates a new FocusManager bound to the given
context
.
Properties
Methods
-
handleInput(
InputEvent event) → ResponseInput -
Handles a generic InputEvent by delegating to tab navigation or
mouse processing as appropriate.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
register(
InteractableComponentInstance c) → void - Registers a component to be considered for focus and hover handling.
-
reset(
) → void - Clears all registered components.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited