performPaint method
RenderLayoutBox real paint things after basiclly paint box model. Override which to paint layout or intrinsic things. Used by RenderReplaced, RenderFlowLayout, RenderFlexLayout.
Implementation
@override
void performPaint(PaintingContext context, Offset offset) {
Offset _accumulateOffsetFromDescendant(RenderObject descendant, RenderObject ancestor) {
Offset sum = Offset.zero;
RenderObject? cur = descendant;
while (cur != null && cur != ancestor) {
final Object? pd = (cur is RenderBox) ? (cur.parentData) : null;
if (pd is ContainerBoxParentData) {
final Offset o = (pd as ContainerBoxParentData).offset;
sum += o;
} else if (pd is RenderLayoutParentData) {
sum += (pd as RenderLayoutParentData).offset;
}
cur = cur.parent as RenderObject?;
}
return sum;
}
for (int i = 0; i < paintingOrder.length; i++) {
RenderBox child = paintingOrder[i];
if (isPositionPlaceholder(child)) continue;
final RenderLayoutParentData childParentData = child.parentData as RenderLayoutParentData;
if (!child.hasSize) continue;
bool restoreFlag = false;
bool previous = false;
final bool promoteHere = (renderStyle as CSSRenderStyle).isDocumentRootBox();
if (promoteHere && child is RenderBoxModel) {
final CSSRenderStyle rs = child.renderStyle;
final int? zi = rs.zIndex;
final bool isPositive = zi != null && zi > 0;
// Suppress painting of descendant positive stacking contexts when painting
// normal-flow/auto/zero buckets; those positives are promoted to be painted
// at this ancestor level to resolve cross-parent ordering.
if (!isPositive) {
previous = rs.suppressPositiveStackingFromDescendants;
rs.suppressPositiveStackingFromDescendants = true;
// Invalidate cached painting order on this child so suppression takes effect.
if (child is RenderLayoutBox) {
child.markChildrenNeedsSort();
} else if (child is RenderWidget) {
child.markChildrenNeedsSort();
}
restoreFlag = true;
}
}
// Compute correct paint offset even if the render box to paint is not a direct child
// of this container (e.g., promoted positive stacking contexts).
final bool direct = identical(child.parent, this);
final Offset localOffset = direct ? childParentData.offset : _accumulateOffsetFromDescendant(child, this);
context.paintChild(child, localOffset + offset);
if (restoreFlag && child is RenderBoxModel) {
(child.renderStyle as CSSRenderStyle).suppressPositiveStackingFromDescendants = previous;
if (child is RenderLayoutBox) {
child.markChildrenNeedsSort();
} else if (child is RenderWidget) {
child.markChildrenNeedsSort();
}
}
}
}