performBoxLayout method
Perform layout with typed box constraints
Subclasses override this instead of performLayout. The default implementation sizes to the maxima, treating an unbounded axis as the corresponding lower bound.
Implementation
@override
void performBoxLayout(BoxConstraints constraints) {
// Self size: take all available space. Unbounded (null max) falls back
// to the lower bound so a ScrollBox always has a definite size.
final w = constraints.maxWidth ?? constraints.minWidth;
final h = constraints.maxHeight ?? constraints.minHeight;
size = Size(w, h);
final c = child;
if (c == null) {
_controller._updateViewportExtent(0);
_controller.updateMaxScrollExtent(0);
return;
}
// Child gets bounded cross-axis, unbounded (null) along scroll axis.
final BoxConstraints childConstraints;
if (_scrollDirection == Axis.vertical) {
childConstraints = BoxConstraints(
minWidth: _viewportWidth,
maxWidth: _viewportWidth,
);
} else {
childConstraints = BoxConstraints(
minHeight: _viewportHeight,
maxHeight: _viewportHeight,
);
}
c.layout(childConstraints);
c
..x = 0
..y = 0;
final contentExtent = _scrollDirection == Axis.vertical
? c.size.height.toDouble()
: c.size.width.toDouble();
final viewportExtent = _scrollDirection == Axis.vertical
? _viewportHeight
: _viewportWidth;
final maxScroll = (contentExtent - viewportExtent).clamp(
0.0,
contentExtent,
);
_controller._updateViewportExtent(viewportExtent);
_controller.updateMaxScrollExtent(maxScroll);
}