hasFocus property

bool hasFocus

Whether this node has input focus.

A FocusNode has focus when it is an ancestor of a node that returns true from hasPrimaryFocus, or it has the primary focus itself.

The hasFocus accessor is different from hasPrimaryFocus in that hasFocus is true if the node is anywhere in the focus chain, but for hasPrimaryFocus the node must to be at the end of the chain to return true.

A node that returns true for hasFocus will receive key events if none of its focused descendants returned true from their onKey handler.

This object is a ChangeNotifier, and notifies its Listenable listeners (registered via addListener) whenever this value changes.

See also:

  • Focus.isAt, which is a static method that will return the focus state of the nearest ancestor Focus widget's focus node.

Implementation

bool get hasFocus => hasPrimaryFocus || (_manager?.primaryFocus?.ancestors?.contains(this) ?? false);