performLayout method

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

Implementation

@override
void performLayout(BoxConstraints constraints) {
  final totalWidth = constraints.maxWidth;
  var flexTotal = 0;
  var nonFlexWidth = 0;
  final expandedChildren = <RenderExpanded>[];

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

  final remaining = (totalWidth - nonFlexWidth).clamp(0, totalWidth);
  var x = 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(alloc, constraints.maxHeight)));
      child.setOffset(x, 0);
      x += alloc;
    } else {
      child.setOffset(x, 0);
      x += child.width;
    }
  }
  setSize(totalWidth, constraints.maxHeight);
}