recommendDeferredLoadingForContext static method

bool recommendDeferredLoadingForContext(
  1. BuildContext context, {
  2. Axis? axis,
})

Provides a heuristic to determine if expensive frame-bound tasks should be deferred for the context at a specific point in time.

Calling this method does not create a dependency on any other widget. This also means that the value returned is only good for the point in time when it is called, and callers will not get updated if the value changes.

The heuristic used is determined by the physics of this Scrollable via ScrollPhysics.recommendDeferredLoading. That method is called with the current ScrollPosition.activity's ScrollActivity.velocity.

The optional Axis allows targeting of a specific Scrollable of that axis, useful when Scrollables are nested. When axis is provided, ScrollPosition.recommendDeferredLoading is called for the nearest Scrollable in that Axis.

If there is no Scrollable in the widget tree above the context, this method returns false.

Implementation

static bool recommendDeferredLoadingForContext(BuildContext context, { Axis? axis }) {
  _ScrollableScope? widget = context.getInheritedWidgetOfExactType<_ScrollableScope>();
  while (widget != null) {
    if (axis == null || axisDirectionToAxis(widget.scrollable.axisDirection) == axis) {
      return widget.position.recommendDeferredLoading(context);
    }
    context = widget.scrollable.context;
    widget = context.getInheritedWidgetOfExactType<_ScrollableScope>();
  }
  return false;
}