performLayout method

  1. @override
void performLayout(
  1. BoxConstraints constraints
)
override

Implementation

@override
void performLayout(BoxConstraints constraints) {
  final totalHeight = constraints.maxHeight;
  var flexTotal = 0;
  var nonFlexHeight = 0;
  final expandedChildren = <RenderExpanded>[];

  for (final child in children) {
    if (child is RenderExpanded) {
      flexTotal += child.flex;
      expandedChildren.add(child);
    } else {
      child.layout(BoxConstraints(
        minWidth: constraints.minWidth,
        maxWidth: constraints.maxWidth,
        minHeight: 0,
        maxHeight: totalHeight,
      ));
      nonFlexHeight += child.height;
    }
  }

  final remaining = (totalHeight - nonFlexHeight).clamp(0, totalHeight);
  var y = 0;
  for (final child in children) {
    if (child is RenderExpanded) {
      final alloc = flexTotal > 0 ? (remaining * child.flex ~/ flexTotal) : 0;
      child.setAllocated(alloc);
      child.layout(BoxConstraints.tight(Size(constraints.maxWidth, alloc)));
      child.setOffset(0, y);
      y += alloc;
    } else {
      child.setOffset(0, y);
      y += child.height;
    }
  }
  setSize(constraints.maxWidth, totalHeight);
}