Clip further painting using a rectangle.
needsCompositing
is whether the child needs compositing. Typically matches the value of RenderObject.needsCompositing for the caller.offset
is the offset from the origin of the canvas' coordinate system to the origin of the caller's coordinate system.clipRect
is rectangle (in the caller's coodinate system) to use to clip the painting done bypainter
.painter
is a callback that will paint with theclipRect
applied. This function calls thepainter
synchronously.
Source
void pushClipRect(bool needsCompositing, Offset offset, Rect clipRect, PaintingContextCallback painter) { final Rect offsetClipRect = clipRect.shift(offset); if (needsCompositing) { _stopRecordingIfNeeded(); final ClipRectLayer clipLayer = new ClipRectLayer(clipRect: offsetClipRect); _appendLayer(clipLayer); final PaintingContext childContext = new PaintingContext._(clipLayer, offsetClipRect); painter(childContext, offset); childContext._stopRecordingIfNeeded(); } else { canvas.save(); canvas.clipRect(offsetClipRect); painter(this, offset); canvas.restore(); } }