Clip further painting using a rectangle.
needsCompositingis whether the child needs compositing. Typically matches the value of RenderObject.needsCompositing for the caller.offsetis the offset from the origin of the canvas' coordinate system to the origin of the caller's coordinate system.clipRectis rectangle (in the caller's coodinate system) to use to clip the painting done bypainter.painteris a callback that will paint with theclipRectapplied. This function calls thepaintersynchronously.
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();
}
}