describeApproximatePaintClip method

  1. @override
Rect describeApproximatePaintClip (covariant RenderSliver child)
override

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.

Implementation

@override
Rect describeApproximatePaintClip(RenderSliver child) {
  final Rect viewportClip = Offset.zero & 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 = viewportClip.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;
      break;
    case AxisDirection.up:
      bottom -= overlapCorrection;
      break;
    case AxisDirection.right:
      left += overlapCorrection;
      break;
    case AxisDirection.left:
      right -= overlapCorrection;
      break;
  }
  return Rect.fromLTRB(left, top, right, bottom);
}