FocusNode class

A leaf node in the focus tree that can receive focus.

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

To request focus, find the FocusScopeNode for the current BuildContext and call the FocusScopeNode.requestFocus method:


If your widget requests focus, be sure to call FocusScope.of(context).reparentIfNeeded(focusNode); in your build method to reparent your FocusNode if your widget moves from one location in the tree to another.


Focus nodes are long-lived objects. For example, if a stateful widget has a focusable child widget, it should create a FocusNode in the State.initState method, and dispose it in the State.dispose method, providing the same FocusNode to the focusable child each time the method is run. In particular, creating a FocusNode each time is invoked will cause the focus to be lost each time the widget is built.

See also:





hasFocus bool
Whether this node has the overall focus. [...]
hashCode int
The hash code for this object. [...]
read-only, inherited
hasListeners bool
Whether any listeners are currently registered. [...]
@protected, read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


consumeKeyboardToken() bool
Removes the keyboard token from this focus node if it has one. [...]
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). [...]
toString() String
Returns a string representation of this object.
unfocus() → void
Cancels any outstanding requests for focus. [...]
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
notifyListeners() → void
Call all the registered listeners. [...]
@protected, @visibleForTesting, inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes. [...]


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