FocusScopeNode class

A subclass of FocusNode that acts as a scope for its descendants, maintaining information about which descendant is currently or was last focused.

Please see the FocusScope and Focus widgets, which are utility widgets that manage their own FocusScopeNodes and FocusNodes, respectively. If they aren't appropriate, FocusScopeNodes can be managed directly.

FocusScopeNode organizes FocusNodes into scopes. Scopes form sub-trees of nodes that can be traversed as a group. Within a scope, the most recent nodes to have focus are remembered, and if a node is focused and then removed, the original node receives focus again.

From a FocusScopeNode, calling setFirstFocus, sets the given focus scope as the focusedChild of this node, adopting if it isn't already part of the focus tree.

null

Key Event Propagation

The FocusManager receives all key events and will pass them to the focused nodes. It starts with the node with the primary focus, and will call the onKey callback for that node. If the callback returns false, indicating that it did not handle the event, the FocusManager will move to the parent of that node and call its onKey. If that onKey returns true, then it will stop propagating the event. If it reaches the root FocusScopeNode, FocusManager.rootScope, the event is discarded.

See also:

  • Focus, a widget that manages a FocusNode and provides access to focus information and actions to its descendant widgets.
  • FocusScope, a widget that manages a FocusScopeNode and provides access to scope information and actions to its descendant widgets.
  • FocusAttachment, a widget that connects a FocusScopeNode to the focus tree.
  • FocusManager, a singleton that manages the focus and distributes key events to focused nodes.
Inheritance

Constructors

FocusScopeNode({String debugLabel, FocusOnKeyCallback onKey })
Creates a FocusScope node. [...]

Properties

focusedChild FocusNode
Returns the child of this node that should receive focus if this scope node receives focus. [...]
read-only
isFirstFocus bool
Returns true if this scope is the focused child of its parent scope.
read-only
nearestScope FocusScopeNode
Returns the nearest enclosing scope node above this node, including this node, if it's a scope. [...]
read-only, override
ancestors Iterable<FocusNode>
An Iterable over the ancestors of this node. [...]
read-only, inherited
children Iterable<FocusNode>
An iterator over the children of this node.
read-only, inherited
context BuildContext
The context that was supplied to attach. [...]
read-only, inherited
debugLabel String
A debug label that is used for diagnostic output. [...]
read / write, inherited
descendants Iterable<FocusNode>
An Iterable over the hierarchy of children below this one, in depth-first order.
read-only, inherited
enclosingScope FocusScopeNode
Returns the nearest enclosing scope node above this node, or null if the node has not yet be added to the focus tree. [...]
read-only, inherited
hasFocus bool
Whether this node has input focus. [...]
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
hasListeners bool
Whether any listeners are currently registered. [...]
@protected, read-only, inherited
hasPrimaryFocus bool
Returns true if this node currently has the application-wide input focus. [...]
read-only, inherited
offset Offset
Returns the global offset to the upper left corner of the attached widget's RenderObject, in logical units.
read-only, inherited
onKey FocusOnKeyCallback
Called if this focus node receives a key event while focused (i.e. when hasFocus returns true). [...]
read-only, inherited
parent FocusNode
Returns the parent node for this object. [...]
read-only, inherited
rect Rect
Returns the global rectangle of the attached widget's RenderObject, in logical units.
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
size Size
Returns the size of the attached widget's RenderObject, in logical units.
read-only, inherited
skipTraversal bool
If true, tells the focus traversal policy to skip over this node for purposes of the traversal algorithm. [...]
read / write, inherited
traversalChildren Iterable<FocusNode>
An iterator over the children that are allowed to be traversed by the FocusTraversalPolicy.
read-only, inherited
traversalDescendants Iterable<FocusNode>
Returns all descendants which do not have the skipTraversal flag set.
read-only, inherited

Methods

autofocus(FocusNode node) → void
If this scope lacks a focus, request that the given node become the focus. [...]
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
override
setFirstFocus(FocusScopeNode scope) → void
Make the given scope the active child scope for this scope. [...]
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes. [...]
inherited
attach(BuildContext context, { FocusOnKeyCallback onKey }) FocusAttachment
Called by the host StatefulWidget to attach a FocusNode to the widget tree. [...]
@mustCallSuper, inherited
consumeKeyboardToken() bool
Removes the keyboard token from this focus node if it has one. [...]
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener and removeListener will throw after the object is disposed). [...]
inherited
focusInDirection(TraversalDirection direction) bool
Request to move the focus to the nearest focus node in the given direction, by calling the FocusTraversalPolicy.inDirection method. [...]
inherited
nextFocus() bool
Request to move the focus to the next focus node, by calling the FocusTraversalPolicy.next method. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
notifyListeners() → void
Call all the registered listeners. [...]
@protected, @visibleForTesting, inherited
previousFocus() bool
Request to move the focus to the previous focus node, by calling the FocusTraversalPolicy.previous method. [...]
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes. [...]
inherited
requestFocus([FocusNode node ]) → void
Requests the primary focus for this node, or for a supplied node, which will also give focus to its ancestors. [...]
inherited
toDiagnosticsNode({String name, DiagnosticsTreeStyle style }) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
inherited
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this object.
inherited
toStringDeep({String prefixLineOne: '', String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this node and its descendants. [...]
inherited
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a one-line detailed description of the object. [...]
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode. [...]
inherited
unfocus() → void
Removes focus from a node that has the primary focus, and cancels any outstanding requests to focus it. [...]
inherited

Operators

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