VisibilityInfo.fromRects constructor

VisibilityInfo.fromRects({
  1. required Key key,
  2. required Rect widgetBounds,
  3. required Rect clipRect,
})

Constructs a VisibilityInfo from widget bounds and a corresponding clipping rectangle.

widgetBounds and clipRect are expected to be in the same coordinate system.

Implementation

factory VisibilityInfo.fromRects({
  required Key key,
  required Rect widgetBounds,
  required Rect clipRect,
}) {
  assert(widgetBounds != null);
  assert(clipRect != null);

  // Compute the intersection in the widget's local coordinates.
  final visibleBounds = widgetBounds.overlaps(clipRect)
      ? widgetBounds.intersect(clipRect).shift(-widgetBounds.topLeft)
      : Rect.zero;

  return VisibilityInfo(
      key: key, size: widgetBounds.size, visibleBounds: visibleBounds);
}