paint method
Paints children, clipped to this box's bounds when layout overflowed.
Without the clip an overflowing child paints into whatever region the
parent assigned to a following sibling — rows interleave and content
escapes its box. Clipping only on recorded overflow mirrors Flutter's
RenderFlex and leaves the ordinary fitting layout untouched.
Implementation
@override
void paint(PaintingContext context, Offset offset) {
if (!_hasOverflow) {
super.paint(context, offset);
return;
}
context.canvas.save();
try {
context.canvas.clipRect(
Rect.fromLTWH(offset.dx + x, offset.dy + y, size.width, size.height),
);
super.paint(context, offset);
} finally {
context.canvas.restore();
}
}