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) {
// Report FCP/LCP when RenderWidget with contentful Flutter widget is first painted
if (renderStyle.target is WidgetElement && firstChild != null && hasSize && !size.isEmpty) {
final widgetElement = renderStyle.target as WidgetElement;
// Check if the widget contains contentful content and get the actual visible area
double contentfulArea = _getContentfulPaintArea(widgetElement);
if (contentfulArea > 0) {
// Report FP first (if not already reported)
widgetElement.ownerDocument.controller.reportFP();
widgetElement.ownerDocument.controller.reportFCP();
// Report LCP candidate with the actual contentful area
widgetElement.ownerDocument.controller.reportLCPCandidate(widgetElement, contentfulArea);
}
}
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) {
sum += (pd as ContainerBoxParentData).offset;
} else if (pd is RenderLayoutParentData) {
sum += (pd as RenderLayoutParentData).offset;
}
cur = cur.parent as RenderObject?;
}
return sum;
}
for (final RenderBox child in paintingOrder) {
if (isPositionPlaceholder(child)) continue;
final RenderLayoutParentData pd = 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;
if (!isPositive) {
previous = rs.suppressPositiveStackingFromDescendants;
rs.suppressPositiveStackingFromDescendants = true;
if (child is RenderLayoutBox) {
child.markChildrenNeedsSort();
} else if (child is RenderWidget) {
child.markChildrenNeedsSort();
}
restoreFlag = true;
}
}
final bool direct = identical(child.parent, this);
final Offset localOffset = direct ? pd.offset : _accumulateOffsetFromDescendant(child, this);
context.paintChild(child, offset + localOffset);
if (restoreFlag && child is RenderBoxModel) {
(child.renderStyle as CSSRenderStyle).suppressPositiveStackingFromDescendants = previous;
if (child is RenderLayoutBox) {
child.markChildrenNeedsSort();
} else if (child is RenderWidget) {
child.markChildrenNeedsSort();
}
}
}
}