maybeOf static method
- BuildContext context
Returns the FocusTraversalPolicy that applies to the FocusNode of the nearest ancestor Focus widget, or null, given a BuildContext.
Will return null if it doesn't find an ancestor Focus or FocusScope widget, or doesn't find a FocusTraversalPolicy that applies to the node.
This function looks up the nearest ancestor Focus (or FocusScope) widget, and uses its FocusNode (or FocusScopeNode) to walk up the focus tree to find the applicable FocusTraversalPolicy for that node.
Calling this function does not create a rebuild dependency because changing the traversal order doesn't change the widget tree, so nothing needs to be rebuilt as a result of an order change.
The FocusTraversalPolicy is set by introducing a FocusTraversalGroup into the widget tree, which will associate a policy with the focus tree under the nearest ancestor Focus widget.
See also:
- maybeOfNode for a similar function that will look for a policy using a given FocusNode.
- of for a similar function that will throw if no FocusTraversalPolicy applies.
Implementation
static FocusTraversalPolicy? maybeOf(BuildContext context) {
final FocusNode? node = Focus.maybeOf(context, scopeOk: true, createDependency: false);
if (node == null) {
return null;
}
return FocusTraversalGroup.maybeOfNode(node);
}