computeThumbMetrics method

({double thumbLength, double thumbOffset}) computeThumbMetrics(
  1. double viewportSize,
  2. double minThumbLength
)

Computes the thumb length and offset for the scrollbar.

Returns a record with thumbLength (the size of the scrollbar thumb) and thumbOffset (its position in the scrollbar track).

Implementation

({double thumbLength, double thumbOffset}) computeThumbMetrics(
  double viewportSize,
  double minThumbLength,
) {
  final thumbLength = max(
    minThumbLength,
    (viewportSize / contentSize) * viewportSize,
  );
  final maxThumbOffset = viewportSize - thumbLength;
  final thumbOffset = scrollProgress * maxThumbOffset;
  return (thumbLength: thumbLength, thumbOffset: thumbOffset);
}