of method

FocusTraversalPolicy of (
  1. BuildContext context,
  2. {bool nullOk: false}
)

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, and nullOk is false.

If nullOk is true, then it will return null if it doesn't find a FocusTraversalGroup ancestor.

Implementation

static FocusTraversalPolicy of(BuildContext context, {bool nullOk = false}) {
  assert(context != null);
  final _FocusTraversalGroupMarker inherited = context?.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupMarker>();
  assert(() {
    if (nullOk) {
      return true;
    }
    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;
}