FocusNode class

A node in the keyboard focus tree.

Represents an interactive leaf or branch in the focus management tree. Key events bubble up the active node path starting from the primary focused leaf up to the root focus scope, until one of the nodes consumes it by returning true.

Core API Reference

Property / Method Description
isFocused Whether this node has keyboard focus.
parent The ancestor focus node in the tree.
children Direct descendants of this focus node.
onKeyEvent Callback to process a key event. Return true to stop propagation.
onFocusChange Callback executed when focus status transitions.
Implementers

Constructors

FocusNode({required String id})
Creates a FocusNode with the given id.

Properties

children List<FocusNode>
The child nodes nested under this node.
final
hasFocus bool
Whether this node has focus.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasPrimaryFocus bool
Whether this node has primary focus, meaning it is focused and none of its children are.
no setter
id String
Unique identifier of the focus node (useful for debugging).
final
isFocused bool
Whether this node currently holds keyboard focus.
getter/setter pair
onFocusChange ↔ void Function(bool hasFocus)?
Callback executed when this focus node gains or loses focus.
getter/setter pair
onKeyEvent bool Function(KeyEvent event)?
Callback executed when a key event hits this node. Return true to consume the keypress and prevent it from bubbling up the tree.
getter/setter pair
parent FocusNode?
The parent focus node, if any.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addChild(FocusNode child) → void
Adds a child focus node to this branch.
bubbleKeyEvent(KeyEvent event) bool
Traverses up from the primary focus node to let nodes consume keypresses.
findFocusedLeaf() FocusNode?
Traverses down the focused path to find the deeply focused leaf node.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
requestFocus() → void
Requests focus for this node, unfocusing other sibling branches recursively.
toString() String
A string representation of this object.
inherited
unfocus() → void
Removes focus from this node and its descendants.

Operators

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