FocusManager class

Manages the focus tree.

The focus tree keeps track of which FocusNode is the user's current keyboard focus. The widget that owns the FocusNode often listens for keyboard events.

The focus manager is responsible for holding the FocusScopeNode that is the root of the focus tree and tracking which FocusNode has the overall focus.

The FocusManager is held by the WidgetsBinding as WidgetsBinding.focusManager, and can be conveniently accessed using the focusManager global accessor.

To find the FocusScopeNode for a given BuildContext, use FocusScope.of.

The FocusManager knows nothing about FocusNodes other than the one that is currently focused (accessible via the primaryFocus global accessor). If a FocusScopeNode is removed, then the FocusManager will attempt to focus the next FocusScopeNode in the focus tree that it maintains, but if the current focus in that FocusScopeNode is null, it will stop there, and no FocusNode will have focus.

See also:

Mixed in types


Creates an object that manages the focus tree. [...]


highlightMode FocusHighlightMode
Indicates the current interaction mode for focus highlights. [...]
highlightStrategy FocusHighlightStrategy
Sets the strategy by which highlightMode is determined. [...]
read / write
primaryFocus FocusNode
The node that currently has the primary focus.
rootScope FocusScopeNode
The root FocusScopeNode in the focus tree. [...]
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


addHighlightModeListener(ValueChanged<FocusHighlightMode> listener) → void
Register a closure to be called when the FocusManager notifies its listeners that the value of highlightMode has changed.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
removeHighlightModeListener(ValueChanged<FocusHighlightMode> listener) → void
Remove a previously registered closure from the list of closures that the FocusManager notifies.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toDiagnosticsNode({String name, DiagnosticsTreeStyle style }) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this object.
toStringDeep({String prefixLineOne: '', String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this node and its descendants. [...]
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a one-line detailed description of the object. [...]
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode. [...]


operator ==(dynamic other) bool
The equality operator. [...]

Static Properties

instance FocusManager
Provides convenient access to the current FocusManager singleton from the WidgetsBinding instance.