performLayout method

void performLayout()

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,
  );
  assert(contentSize.width.isFinite && contentSize.height.isFinite);
  size = viewportSize;
  if (needsSorting) {
    _sortChildren();
  }
}