A scope for managing the focus state of descendant widgets.
The focus represents where the user's attention is directed. If the use interacts with the system in a way that isn't visually directed at a particular widget (e.g., by typing on a keyboard), the interaction is directed to the currently focused widget.
The focus system consists of a tree of Focus widgets, which is embedded in the widget tree. Focus widgets themselves can be focused in their enclosing Focus widget, which means that their subtree is the one that has the current focus. For example, a dialog creates a Focus widget to maintain focus within the dialog. When the dialog closes, its Focus widget is removed from the tree and focus is restored to whichever other part of the Focus tree previously had focus.
In addition to tracking which enclosed Focus widget has focus, each Focus widget also tracks a GlobalKey, which represents the currently focused widget in this part of the focus tree. If this Focus widget is the currently focused subtree of the focus system (i.e., the path from it to the root is focused at each level and it hasn't focused any of its enclosed Focus widgets), then the widget this this global key actually has the focus in the entire system.
- Inheritance
- Object
- Widget
- StatefulWidget
- Focus
Static Properties
- debugOnlyFocusedKey → GlobalKey
-
The key that currently has focus globally in the entire focus tree.
read / write
Static Methods
-
at(
BuildContext context, { bool autofocus: false }) → bool -
Whether the focus is current at the given context.
-
clear(
BuildContext context) → void -
Unfocuses the currently focused widget (if any) in the Focus that most tightly encloses the given context.
-
moveScopeTo(
GlobalKey key, { BuildContext context }) → void -
Focuses a particular focus scope, identified by its GlobalKey.
-
moveTo(
GlobalKey key) → void -
Focuses a particular widget, identified by its GlobalKey. The widget must be in the widget tree.
Constructors
Properties
- child → Widget
-
The widget below this widget in the tree.
read-only - initiallyFocusedScope → GlobalKey
-
The global key of the Focus widget below this widget in the tree that will be focused initially.
read-only - hashCode → int
-
Get a hash code for this object.
read-only, inherited - key → Key
-
Controls how one widget replaces another widget in the tree.
read-only, inherited - runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Operators
-
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
createState(
) → _FocusState -
Creates the mutable state for this widget at a given location in the tree.
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited -
debugFillDescription(
List<String> description) → void -
Add additional information to the given description for use by toString.
inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
toString(
) → String -
Returns a string representation of this object.
inherited -
toStringShort(
) → String -
A short, textual description of this widget.
inherited