paint method
Paint this render object into the given context at the given offset.
Subclasses should override this method to provide a visual appearance for themselves. The render object's local coordinate system is axis-aligned with the coordinate system of the context's canvas and the render object's local origin (i.e, x=0 and y=0) is placed at the given offset in the context's canvas.
Do not call this function directly. If you wish to paint yourself, call
markNeedsPaint instead to schedule a call to this function. If you wish
to paint one of your children, call PaintingContext.paintChild on the
given context
.
When painting one of your children (via a paint child function on the given context), the current canvas held by the context might change because draw operations before and after painting children might need to be recorded on separate compositing layers.
Implementation
@override
void paint(PaintingContext context, Offset offset) {
_updateClip();
if (shouldClip) {
if (clipSliverOnly && background != null) {
context.paintChild(background!, offset + _bufferRect!.topLeft);
}
if (_bufferRect!.left == 0.0 && _bufferRect!.top == 0.0) {
context.pushClipPath(needsCompositing, offset,
Offset.zero & _bufferRect!.size, _clipPath!, (context, offset) {
if (!clipSliverOnly && background != null) {
context.paintChild(background!, offset);
}
if (sliver != null) {
context.paintChild(sliver!, offset);
}
if (!clipSliverOnly && foreground != null) {
context.paintChild(foreground!, offset);
}
});
} else {
final transform =
Matrix4.translationValues(_bufferRect!.left, _bufferRect!.top, 0);
context.pushTransform(needsCompositing, Offset.zero, transform,
(context, newOffset) {
context.pushClipPath(
needsCompositing,
offset,
Offset.zero & _bufferRect!.size,
_clipPath!,
(context, offset) {
offset -= _bufferRect!.topLeft;
if (!clipSliverOnly && background != null) {
context.paintChild(background!, offset + _bufferRect!.topLeft);
}
if (sliver != null) {
context.paintChild(sliver!, offset);
}
if (!clipSliverOnly && foreground != null) {
context.paintChild(foreground!, offset + _bufferRect!.topLeft);
}
},
clipBehavior: clipBehavior,
oldLayer: layer as ClipPathLayer?,
);
});
}
if (clipSliverOnly && foreground != null) {
context.paintChild(foreground!, offset + _bufferRect!.topLeft);
}
} else {
if (background != null) {
context.paintChild(background!, offset + _bufferRect!.topLeft);
}
if (sliver != null) {
context.paintChild(sliver!, offset);
}
if (foreground != null) {
context.paintChild(foreground!, offset + _bufferRect!.topLeft);
}
}
}