of static method

ScrollController of(
  1. BuildContext context
)

Returns the ScrollController most closely associated with the given context.

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

Calling this method will create a dependency on the closest PrimaryScrollController in the context.

See also:

Implementation

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