of static method

CoordinatorLayoutState? of(
  1. BuildContext context, {
  2. bool nullOk = false,
})

Implementation

static CoordinatorLayoutState? of(BuildContext context,
    {bool nullOk = false}) {
  final CoordinatorLayoutState? result =
      context.findAncestorStateOfType<CoordinatorLayoutState>();
  if (nullOk || result != null) return result;
  throw FlutterError.fromParts(<DiagnosticsNode>[
    ErrorSummary(
        'CoordinatorLayoutState.of() called with a context that does not contain a CoordinatorLayoutState.'),
    ErrorDescription(
        'No CoordinatorLayoutState ancestor could be found starting from the context that was passed to CoordinatorLayoutState.of(). '
        'This usually happens when the context provided is from the same StatefulWidget as that '
        'whose build function actually creates the CoordinatorLayoutState widget being sought.'),
    ErrorHint(
        'There are several ways to avoid this problem. The simplest is to use a Builder to get a '
        'context that is "under" the CoordinatorLayoutState. For an example of this, please see the '
        'documentation for CoordinatorLayoutState.of():\n'
        '  https://api.flutter.dev/flutter/material/CoordinatorLayoutState/of.html'),
    ErrorHint(
        'A more efficient solution is to split your build function into several widgets. This '
        'introduces a new context from which you can obtain the CoordinatorLayoutState. In this solution, '
        'you would have an outer widget that creates the CoordinatorLayoutState populated by instances of '
        'your new inner widgets, and then in these inner widgets you would use CoordinatorLayoutState.of().\n'
        'A less elegant but more expedient solution is assign a GlobalKey to the CoordinatorLayoutState, '
        'then use the key.currentState property to obtain the CoordinatorLayoutStateState rather than '
        'using the CoordinatorLayoutState.of() function.'),
    context.describeElement('The context used was')
  ]);
}