of static method

TwoDimensionalScrollableState of(
  1. BuildContext context
)

The state from the closest instance of this class that encloses the given context.

Typical usage is as follows:

TwoDimensionalScrollableState scrollable = TwoDimensionalScrollable.of(context);

Calling this method will create a dependency on the closest TwoDimensionalScrollable in the context. The internal Scrollables can be accessed through TwoDimensionalScrollableState.verticalScrollable and TwoDimensionalScrollableState.horizontalScrollable.

If no TwoDimensionalScrollable ancestor is found, then this method will assert in debug mode, and throw an exception in release mode.

Alternatively, Scrollable.of can be used by providing the desired Axis to the axis parameter.

See also:

Implementation

static TwoDimensionalScrollableState of(BuildContext context) {
  final TwoDimensionalScrollableState? scrollableState = maybeOf(context);
  assert(() {
    if (scrollableState == null) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary(
          'TwoDimensionalScrollable.of() was called with a context that does '
          'not contain a TwoDimensionalScrollable widget.\n'
        ),
        ErrorDescription(
          'No TwoDimensionalScrollable widget ancestor could be found starting '
          'from the context that was passed to TwoDimensionalScrollable.of(). '
          'This can happen because you are using a widget that looks for a '
          'TwoDimensionalScrollable ancestor, but no such ancestor exists.\n'
          'The context used was:\n'
          '  $context',
        ),
      ]);
    }
    return true;
  }());
  return scrollableState!;
}