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 or Shift+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

  1. Registration — Components must be registered via register each frame before input is handled.
  2. Handling inputhandleInput is called with incoming InputEvents.
  3. Updating state — The focus manager mutates internal focus/hover state and produces a ResponseInput marking components that should be re-rendered.
  4. 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:

Implemented types

Constructors

FocusManager.new({required Context context})
Creates a new FocusManager bound to the given context.

Properties

context Context
The rendering and event Context this focus manager operates within.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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