clipRect method

void clipRect({
  1. required Rect rect,
  2. required VoidCallback paint,
  3. Clip clipBehavior = Clip.antiAlias,
  4. Offset offset = Offset.zero,
  5. Rect? bounds,
  6. LayerKey<Layer>? key,
})

Pushes a ClipRectLayer to the compositing tree, calling paint to paint on top of the layer.

The bounds argument defines the bounds in which the paint should paint, this is useful for debugging tools and does not affect rendering.

See also:

Implementation

void clipRect({
  required Rect rect,
  required VoidCallback paint,
  Clip clipBehavior = Clip.antiAlias,
  Offset offset = Offset.zero,
  Rect? bounds,
  LayerKey? key,
}) {
  final offsetClipRect = rect.shift(offset + _render.paintOffset!);
  ClipRectLayer layer;
  if (key?.layer is ClipRectLayer) {
    layer = (key!.layer! as ClipRectLayer)
      ..clipRect = offsetClipRect
      ..clipBehavior = clipBehavior;
  } else {
    layer = ClipRectLayer(
      clipRect: offsetClipRect,
      clipBehavior: clipBehavior,
    );
    key?.layer = layer;
  }
  push(layer: layer, paint: paint, offset: offset, bounds: bounds);
}