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() {
final w = constraints.hasBoundedWidth ? constraints.maxWidth : null;
final laid = _lay(_Pass.layout, w);
_laid = laid;
_disposePainters();
size = constraints.constrain(Size(w ?? laid.width, laid.height));
// The containing block of every relative box in the flow (see
// [InlineBox.offsetShare]), before any shift is read.
_flat.boxes.first.width = size.width;
final shifts = <int, Offset>{
for (final op in laid.ops)
if (op case _AtomOp(:final atom, :final box)) atom: box.shift,
};
// A POINT ON NO LINE -- a flow of nothing is no line (CSS 2.1 9.4.2)
// -- is where the line would have started, at the flow's top, as what
// is placed against a box on no line is (below).
final points = {
for (final it in _flat.items)
if (it.kind == _Kind.mark) it.atom,
};
var kid = firstChild;
var i = 0;
while (kid != null && i < laid.atomAt.length) {
final data = kid.parentData! as InlineFlowParentData;
final at = laid.atomAt[i];
data
..offset = at ?? (points.contains(i) ? Offset(_lineStart, 0) : Offset.zero)
..shift = shifts[i] ?? Offset.zero
..shown = at != null && !laid.hidden.contains(i);
kid = childAfter(kid);
i++;
}
// WHAT IS PLACED AGAINST A BOX is laid out its containing block, the
// padding box from its first piece's start to its last one's end. A
// box on no line -- a flow of nothing, which is no line (CSS 2.1
// 9.4.2) -- is a point where the line would have started, as
// `text-align` puts it, at the flow's top; what is placed against it
// is painted after all else, faded as the boxes round it fade.
_placedKids = {};
_orphans = [];
for (final node in _placedOf(_content)) {
if (kid == null) break;
final data = kid.parentData! as InlineFlowParentData;
final frags = [
for (final f in laid.fragments)
if (identical(f.box.node, node)) f,
];
final Rect cb;
final Offset shift;
if (frags.isNotEmpty) {
final border = node.decoration?.padding.resolve(TextDirection.ltr) ?? EdgeInsets.zero;
final first = frags.first.rect, last = frags.last.rect;
final left = first.left + border.left;
cb = Rect.fromLTRB(
left,
first.top + border.top,
math.max(left, last.right - border.right),
math.max(first.top + border.top, last.bottom - border.bottom),
);
shift = frags.first.box.shift;
_placedKids![frags.first.box] = kid;
} else {
cb = Rect.fromLTWH(_lineStart, 0, 0, 0);
final (moved, alpha) = _around(node);
shift = moved;
if (alpha > 0) _orphans!.add((kid, alpha));
}
kid.layout(BoxConstraints.tight(cb.size));
data
..offset = cb.topLeft
..shift = shift
..shown = true;
kid = childAfter(kid);
}
while (kid != null) {
(kid.parentData! as InlineFlowParentData).shown = false;
kid = childAfter(kid);
}
}