of method Null safety

FocusTraversalPolicy of(
  1. BuildContext context
)

Returns the focus policy set by the FocusTraversalGroup that most tightly encloses the given BuildContext.

It 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.

Will assert if no FocusTraversalGroup ancestor is found.

See also:

Implementation

static FocusTraversalPolicy of(BuildContext context) {
  assert(context != null);
  final _FocusTraversalGroupMarker? inherited = context.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupMarker>();
  assert(() {
    if (inherited == null) {
      throw FlutterError(
        'Unable to find a FocusTraversalGroup widget in the context.\n'
        'FocusTraversalGroup.of() was called with a context that does not contain a '
        'FocusTraversalGroup.\n'
        'No FocusTraversalGroup ancestor could be found starting from the context that was '
        'passed to FocusTraversalGroup.of(). This can happen because there is not a '
        'WidgetsApp or MaterialApp widget (those widgets introduce a FocusTraversalGroup), '
        'or it can happen if the context comes from a widget above those widgets.\n'
        'The context used was:\n'
        '  $context',
      );
    }
    return true;
  }());
  return inherited!.policy;
}