performLayout method
void
performLayout()
Performs the layout calculation for this box and its children.
This method computes the positions and sizes of all children based on the layout algorithm and constraints.
Implementation
void performLayout() {
bool needsSorting = false;
LayoutHandle layoutHandle = boxLayout.createLayoutHandle(this);
Box? child = firstChild;
while (child != null) {
final childParentData = child.parentData;
if (childParentData.paintOrder != null) {
needsSorting = true;
}
childParentData.cache = layoutHandle.setupCache();
child = childParentData.nextSibling;
}
final layoutConstraints = constraints;
LayoutSize contentSize = layoutHandle.performLayout(
layoutConstraints,
);
final viewportSize = layoutConstraints.constrain(contentSize);
_contentSize = contentSize;
assert(() {
bool hasCache = true;
Box? child = firstChild;
while (child != null) {
if (child.parentData.cache == null) {
hasCache = false;
break;
}
child = child.parentData.nextSibling;
}
return hasCache;
}(), 'Not all children have layout cache after layout.');
_contentBounds = layoutHandle.performPositioning(
viewportSize,
contentSize,
ParentRect.zero,
);
assert(contentSize.width.isFinite && contentSize.height.isFinite);
size = viewportSize;
if (needsSorting) {
_sortChildren();
}
}