performLayout method
Do the work of computing the layout for this render object.
Do not call this function directly: call layout instead. This function is called by layout when there is actually work to be done by this render object during layout. The layout constraints provided by your parent are available via the constraints getter.
If sizedByParent is true, then this function should not actually change the dimensions of this render object. Instead, that work should be done by performResize. If sizedByParent is false, then this function should both change the dimensions of this render object and instruct its children to layout.
In implementing this function, you must call layout on each of your children, passing true for parentUsesSize if your layout information is dependent on your child's layout information. Passing true for parentUsesSize ensures that this render object will undergo layout if the child undergoes layout. Otherwise, the child can change its layout information without informing this render object.
Some special RenderObject subclasses (such as the one used by OverlayPortal.overlayChildLayoutBuilder) call applyPaintTransform in their performLayout implementation. To ensure such RenderObjects get the up-to-date paint transform, RenderObject subclasses should typically update the paint transform (as reported by applyPaintTransform) in this method instead of paint.
Implementation
@override
void performLayout() {
super.performLayout();
// For sticky positioned elements, the placeholder must reserve space in the
// normal flow equivalent to the element's own used size so that subsequent
// content does not collapse upward. Absolute/fixed placeholders remain size 0.
final RenderBoxModel? rbm = positioned;
final bool isSticky = rbm != null && rbm.renderStyle.position == CSSPositionType.sticky;
if (isSticky) {
double phWidth = size.width;
double phHeight = size.height;
// Prefer explicit CSS width/height if specified; otherwise fall back to any
// known box size from a previous layout, but only when the positioned box
// has a valid size. Avoid reading boxSize before the child has laid out to
// prevent assertion failures.
final CSSRenderStyle rs = rbm!.renderStyle;
if (rs.width.isNotAuto) {
phWidth = rs.width.computedValue;
} else if (rbm.hasSize && rbm.boxSize != null) {
phWidth = rbm.boxSize!.width;
}
if (rs.height.isNotAuto) {
phHeight = rs.height.computedValue;
} else if (rbm.hasSize && rbm.boxSize != null) {
phHeight = rbm.boxSize!.height;
}
// Constrain to incoming constraints if any (typically unconstrained in flow).
final BoxConstraints c = constraints;
final Size desired = Size(phWidth, phHeight);
size = c.constrain(desired);
}
}