Skip to main content

FocusNode

Struct FocusNode 

Source
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§

Source§

impl FocusNode

Source

pub fn new(app: &mut App) -> Ref<FocusNode>

Creates a focus node.

Trait Implementations§

Source§

impl ChangeNotifier for FocusNode

Source§

fn change_notifier_data(&self) -> &ChangeNotifierData

Source§

fn change_notifier_data_mut(&mut self) -> &mut ChangeNotifierData

Source§

fn will_add_listener(self: Handle<Self>, app: &mut App)

Runs before the listener is stored. Dart overrides of addListener that work before super.addListener go here.
Source§

fn did_remove_listener(self: Handle<Self>, app: &mut App)

Runs after the listener is removed. Dart overrides of removeListener that work after super.removeListener go here.
Source§

impl FocusNodeLeaf for FocusNode

Source§

fn focus_node_data(self: Handle<Self>, app: &App) -> &FocusNodeData

Dart’s FocusNode fields, held under the field focus_node (focus_node_accessors!).
Source§

fn focus_node_data_mut(self: Handle<Self>, app: &mut App) -> &mut FocusNodeData

Source§

fn as_node(self: Handle<Self>) -> AnyFocusNode

This node as the erased AnyFocusNode — what to pass where a Dart API takes a FocusNode. Read more
Source§

fn as_scope(self: Handle<Self>) -> Option<Handle<FocusScopeNode>>

Dart’s node is FocusScopeNode.
Source§

fn nearest_scope( self: Handle<Self>, app: &mut App, ) -> Option<Handle<FocusScopeNode>>

Returns the nearest enclosing scope node above this node, including this node, if it’s a scope.
Source§

fn descendants_are_focusable(self: Handle<Self>, app: &App) -> bool

If false, will disable focus for all of this node’s descendants.
Source§

fn traversal_children(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>

An iterator over the children that are allowed to be traversed by the FocusTraversalPolicy.
Source§

fn traversal_descendants(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>

Returns all descendants which do not have the 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)

Requests the primary focus for this node; overridden by FocusScopeNode.
Source§

fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s 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>>

Dart’s FocusNode.debugDescribeChildren: each child, named Child 1, Child 2, ….
Source§

fn to_string_short(self: Handle<Self>, app: &App) -> String

Dart’s FocusNode.toStringShort: the identity, then the debug label and the focus markers.
Source§

fn skip_traversal(self: Handle<Self>, app: &mut App) -> bool

Source§

fn set_skip_traversal(self: Handle<Self>, app: &mut App, value: bool)

Source§

fn can_request_focus(self: Handle<Self>, app: &mut App) -> bool

Source§

fn set_can_request_focus(self: Handle<Self>, app: &mut App, value: bool)

Source§

fn set_descendants_are_focusable(self: Handle<Self>, app: &mut App, value: bool)

Source§

fn descendants_are_traversable(self: Handle<Self>, app: &App) -> bool

Source§

fn set_descendants_are_traversable( self: Handle<Self>, app: &mut App, value: bool, )

Source§

fn context(self: Handle<Self>, app: &App) -> Option<BuildContext>

Source§

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>, )

Source§

fn debug_label(self: Handle<Self>, app: &App) -> Option<String>

Source§

fn set_debug_label(self: Handle<Self>, app: &mut App, value: Option<String>)

Source§

fn parent(self: Handle<Self>, app: &App) -> Option<AnyFocusNode>

Source§

fn children(self: Handle<Self>, app: &App) -> Vec<AnyFocusNode>

Source§

fn descendants(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>

Source§

fn ancestors(self: Handle<Self>, app: &mut App) -> Vec<AnyFocusNode>

Source§

fn has_focus(self: Handle<Self>, app: &mut App) -> bool

Source§

fn has_primary_focus(self: Handle<Self>, app: &App) -> bool

Source§

fn highlight_mode(self: Handle<Self>, app: &mut App) -> FocusHighlightMode

Source§

fn enclosing_scope( self: Handle<Self>, app: &mut App, ) -> Option<Handle<FocusScopeNode>>

Source§

fn size(self: Handle<Self>, app: &App) -> Size

Source§

fn offset(self: Handle<Self>, app: &App) -> Offset

Source§

fn rect(self: Handle<Self>, app: &App) -> Rect

Source§

fn unfocus(self: Handle<Self>, app: &mut App, disposition: UnfocusDisposition)

Source§

fn consume_keyboard_token(self: Handle<Self>, app: &mut App) -> bool

Source§

fn attach( self: Handle<Self>, app: &mut App, context: Option<BuildContext>, on_key_event: Option<FocusOnKeyEventCallback>, ) -> Ref<FocusAttachment>

Source§

fn dispose(self: Handle<Self>, app: &mut App)

Source§

fn request_focus(self: Handle<Self>, app: &mut App, node: Option<AnyFocusNode>)

Auto Trait Implementations§

§

impl !RefUnwindSafe for FocusNode

§

impl !Send for FocusNode

§

impl !Sync for FocusNode

§

impl !UnwindSafe for FocusNode

§

impl Forget for FocusNode

§

impl Freeze for FocusNode
where *const u8 is !null: Freeze, PhantomData<Option<Listener>>: Freeze, *const RcInner<Cell<usize>> is !null: Freeze, PhantomData<RcInner<Cell<usize>>>: Freeze, NonZero<u32>: Freeze, &'static ElementVTable: Freeze, *const RcInner<dyn Fn(&mut App, AnyFocusNode, &KeyEvent) -> KeyEventResult> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyFocusNode, &KeyEvent) -> KeyEventResult>>: Freeze, PhantomData<fn() -> FocusManager>: Freeze, PhantomData<AnyFocusNode>: Freeze, PhantomData<Retained<AnyFocusNode>>: Freeze, &'static FocusNodeVTable: Freeze, PhantomData<u8>: Freeze, PhantomData<fn() -> FocusAttachment>: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, PhantomData<fn() -> FocusScopeNode>: Freeze,

§

impl Move for FocusNode

§

impl Unpin for FocusNode
where *const u8 is !null: Unpin, Rc<dyn Fn(&mut App)>: Unpin, NonZero<u32>: Unpin, *const (): Unpin, Rc<Cell<usize>>: Unpin, &'static ElementVTable: Unpin, Rc<dyn Fn(&mut App, AnyFocusNode, &KeyEvent) -> KeyEventResult>: Unpin, &'static FocusNodeVTable: Unpin, Rc<Keep>: Unpin,

§

impl UnsafeUnpin for FocusNode

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ListenableObject for T
where T: ChangeNotifier,

Source§

fn add_listener(self: Handle<T>, app: &mut App, listener: Listener)

Register a closure to be called when the object notifies its listeners.
Source§

fn remove_listener(self: Handle<T>, app: &mut App, listener: &Listener)

Remove a previously registered closure from the list of closures that the object notifies.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>