pub struct FocusNode { /* private fields */ }Expand description
An object that can be used by a stateful widget to obtain the keyboard focus and to handle keyboard events.
Please see the Focus and FocusScope widgets, which are utility widgets that manage
their own FocusNodes and FocusScopeNodes, respectively. If they aren’t appropriate,
FocusNodes can be managed directly, but doing this is rare.
FocusNodes are persistent objects that form a focus tree that is a representation of
the widgets in the hierarchy that are interested in focus. A focus node might need to be
created if it is passed in from an ancestor of a Focus widget to control the focus of the
children from the ancestor, or a widget might need to host one if the widget subsystem is
not being used, or if the Focus and FocusScope widgets provide insufficient control.
FocusNodes are organized into scopes (see FocusScopeNode), which form sub-trees of
nodes that restrict traversal to a group of nodes. Within a scope, the most recent nodes to
have focus are remembered, and if a node is focused and then unfocused, the previous node
receives focus again.
The focus node hierarchy can be traversed using the AnyFocusNode::parent,
AnyFocusNode::children, AnyFocusNode::ancestors and AnyFocusNode::descendants
accessors.
FocusNodes are ChangeNotifiers, so a listener can be registered to receive a
notification when the focus changes. Listeners will also be notified when
AnyFocusNode::skip_traversal, AnyFocusNode::can_request_focus,
AnyFocusNode::descendants_are_focusable, and
AnyFocusNode::descendants_are_traversable properties are updated.
§Lifecycle
There are several actors involved in the lifecycle of a FocusNode / FocusScopeNode.
They are created and disposed by their owner, attached, detached, and re-parented using a
FocusAttachment by their host (which must be owned by the State of a
StatefulWidget), and they are managed by the FocusManager.
Dart’s optional constructor arguments (debugLabel, onKeyEvent, skipTraversal,
canRequestFocus, descendantsAreFocusable, descendantsAreTraversable) are the node’s
setters; each of them is a public setter in Dart too, and none of them notifies before the
node joins a tree.
Implementations§
Trait Implementations§
Source§impl ChangeNotifier for FocusNode
impl ChangeNotifier for FocusNode
fn change_notifier_data(&self) -> &ChangeNotifierData
fn change_notifier_data_mut(&mut self) -> &mut ChangeNotifierData
Source§fn will_add_listener(self: Handle<Self>, app: &mut App)
fn will_add_listener(self: Handle<Self>, app: &mut App)
addListener that
work before super.addListener go here.Source§fn did_remove_listener(self: Handle<Self>, app: &mut App)
fn did_remove_listener(self: Handle<Self>, app: &mut App)
removeListener that
work after super.removeListener go here.Source§impl FocusNodeLeaf for FocusNode
impl FocusNodeLeaf for FocusNode
Source§fn focus_node_data(self: Handle<Self>, app: &App) -> &FocusNodeData
fn focus_node_data(self: Handle<Self>, app: &App) -> &FocusNodeData
Source§fn focus_node_data_mut(self: Handle<Self>, app: &mut App) -> &mut FocusNodeData
fn focus_node_data_mut(self: Handle<Self>, app: &mut App) -> &mut FocusNodeData
focus_node_data.Source§fn as_node(self: Handle<Self>) -> AnyFocusNode
fn as_node(self: Handle<Self>) -> AnyFocusNode
Source§fn as_scope(self: Handle<Self>) -> Option<Handle<FocusScopeNode>>
fn as_scope(self: Handle<Self>) -> Option<Handle<FocusScopeNode>>
node is FocusScopeNode.Source§fn nearest_scope(
self: Handle<Self>,
app: &mut App,
) -> Option<Handle<FocusScopeNode>>
fn nearest_scope( self: Handle<Self>, app: &mut App, ) -> Option<Handle<FocusScopeNode>>
Source§fn descendants_are_focusable(self: Handle<Self>, app: &App) -> bool
fn descendants_are_focusable(self: Handle<Self>, app: &App) -> bool
Source§fn traversal_children(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>
fn traversal_children(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>
FocusTraversalPolicy.Source§fn traversal_descendants(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>
fn traversal_descendants(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>
skip_traversal and do have the
can_request_focus flag set.Source§fn do_request_focus(self: Handle<Self>, app: &mut App, find_first_focus: bool)
fn do_request_focus(self: Handle<Self>, app: &mut App, find_first_focus: bool)
FocusScopeNode.Source§fn debug_fill_properties(
self: Handle<Self>,
app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, )
FocusNode.debugFillProperties, which FocusScopeNode’s own body calls where
Dart writes super.Source§fn debug_describe_children(
self: Handle<Self>,
app: &mut App,
) -> Vec<Rc<dyn DiagnosticsNode>>
fn debug_describe_children( self: Handle<Self>, app: &mut App, ) -> Vec<Rc<dyn DiagnosticsNode>>
FocusNode.debugDescribeChildren: each child, named Child 1, Child 2, ….Source§fn to_string_short(self: Handle<Self>, app: &App) -> String
fn to_string_short(self: Handle<Self>, app: &App) -> String
FocusNode.toStringShort: the identity, then the debug label and the focus
markers.Source§fn on_key_event(
self: Handle<Self>,
app: &App,
) -> Option<FocusOnKeyEventCallback>
fn on_key_event( self: Handle<Self>, app: &App, ) -> Option<FocusOnKeyEventCallback>
Source§fn set_on_key_event(
self: Handle<Self>,
app: &mut App,
value: Option<FocusOnKeyEventCallback>,
)
fn set_on_key_event( self: Handle<Self>, app: &mut App, value: Option<FocusOnKeyEventCallback>, )
Source§fn parent(self: Handle<Self>, app: &App) -> Option<AnyFocusNode>
fn parent(self: Handle<Self>, app: &App) -> Option<AnyFocusNode>
AnyFocusNode::parent.Source§fn descendants(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>
fn descendants(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>
Source§fn highlight_mode(self: Handle<Self>, app: &mut App) -> FocusHighlightMode
fn highlight_mode(self: Handle<Self>, app: &mut App) -> FocusHighlightMode
Source§fn enclosing_scope(
self: Handle<Self>,
app: &mut App,
) -> Option<Handle<FocusScopeNode>>
fn enclosing_scope( self: Handle<Self>, app: &mut App, ) -> Option<Handle<FocusScopeNode>>
Source§fn attach(
self: Handle<Self>,
app: &mut App,
context: Option<BuildContext>,
on_key_event: Option<FocusOnKeyEventCallback>,
) -> Ref<FocusAttachment>
fn attach( self: Handle<Self>, app: &mut App, context: Option<BuildContext>, on_key_event: Option<FocusOnKeyEventCallback>, ) -> Ref<FocusAttachment>
AnyFocusNode::attach.