calculatePanelSizes method
Calculates the sizes of the child panel when they change, or when the parent viewport dimensions change
Implementation
void calculatePanelSizes(BoxConstraints constraints, double dividerWidth) {
if (panels.isEmpty) return;
final axisSize =
axis == Axis.horizontal ? constraints.maxWidth : constraints.maxHeight;
// Calculate panel sizes, if we have to
// Calculate new sizes if:
// 1. it's the first layout or
// 2. the number of panels changed
if (panelSizes == null ||
panelSizes!.isEmpty ||
panelSizes!.length != panels.length) {
panelSizes = _computeInitialSizes(axisSize, dividerWidth);
}
// Otherwise, resize the panels keeping their aspect ratios
else {
var newPanelSize = (axis == Axis.horizontal
? constraints.maxWidth
: constraints.maxHeight);
final panelSize = (axis == Axis.horizontal
? this.constraints?.maxWidth
: this.constraints?.maxHeight) ??
newPanelSize;
if (newPanelSize != panelSize) {
// To account for rounding errors, the last panel should take up
// the remaining available space, this accumulates the amount of space used up
var usedSize = 0.0;
for (var i = 0; i < panelSizes!.length; i++) {
if (i != panelSizes!.length - 1) {
panelSizes![i] = panelSizes![i] * newPanelSize / panelSize;
usedSize += panelSizes![i];
} else {
panelSizes![i] =
newPanelSize - dividerWidth * (panels.length - 1) - usedSize;
}
}
}
}
}