performLayout method
Hook for subclasses to perform layout within the given constraints.
Implementation
@override
Size performLayout(BoxConstraints constraints) {
final sb = widget as ScrollBar;
final width = constraints.hasBoundedWidth
? constraints.maxWidth
: (sb.direction == LayoutDirection.vertical ? 1 : 80);
final height = constraints.hasBoundedHeight
? constraints.maxHeight
: (sb.direction == LayoutDirection.vertical ? 80 : 1);
trackHeight = sb.direction == LayoutDirection.vertical ? height : width;
final total = sb._totalExtent;
final view = sb._viewportExtent;
if (total <= 0) {
thumbHeight = 0;
thumbPos = 0;
} else {
final double ratio = (view / total).clamp(0.0, 1.0);
thumbHeight = (ratio * trackHeight).round().clamp(1, trackHeight);
final int maxScrollOffset = total - view;
thumbPos = 0;
if (maxScrollOffset > 0) {
final double scrollRatio = (sb._scrollOffset / maxScrollOffset).clamp(
0.0,
1.0,
);
thumbPos = (scrollRatio * (trackHeight - thumbHeight)).round().clamp(
0,
trackHeight - thumbHeight,
);
}
}
return constraints.constrain(Size(width, height));
}