describeApproximatePaintClip method

  1. @override
Rect describeApproximatePaintClip (covariant RenderSliver child)

Returns a rect in this object's coordinate system that describes the approximate bounding box of the clip rect that would be applied to the given child during the paint phase, if any.

Returns null if the child would not be clipped.

This is used in the semantics phase to avoid including children that are not physically visible.


Rect describeApproximatePaintClip(RenderSliver child) {
  final Rect viewportClip = & size;
  if (child.constraints.overlap == 0) {
    return viewportClip;

  // Adjust the clip rect for this sliver by the overlap from the previous sliver.
  double left = viewportClip.left;
  double right = viewportClip.right;
  double top =;
  double bottom = viewportClip.bottom;
  final double startOfOverlap = child.constraints.viewportMainAxisExtent - child.constraints.remainingPaintExtent;
  final double overlapCorrection = startOfOverlap + child.constraints.overlap;
  switch (applyGrowthDirectionToAxisDirection(axisDirection, child.constraints.growthDirection)) {
    case AxisDirection.down:
      top += overlapCorrection;
    case AxisDirection.up:
      bottom -= overlapCorrection;
    case AxisDirection.right:
      left += overlapCorrection;
    case AxisDirection.left:
      right -= overlapCorrection;
  return Rect.fromLTRB(left, top, right, bottom);