visibleRowRange function
The row window (viewport plus cacheExtent buffer on each side) that should
be built for the given scroll position, out of rowCount total rows.
Shared by all three virtualized layers (GridUnpinnedQuadrant, GridPinnedQuadrant, FullWidthRowBandLayer) so a pinned cell, an unpinned cell and a group band belonging to the same row always agree on the window.
cacheExtent is clamped to 500px under kDebugMode: pre-rendering a large
buffer is what keeps release-build flings smooth, but it makes debug builds
and hot reload sluggish for no benefit.
Implementation
VisibleRowRange visibleRowRange({
required double scrollOffset,
required double viewportExtent,
required double cacheExtent,
required double rowHeight,
required int rowCount,
}) {
final effectiveCacheExtent = kDebugMode
? cacheExtent.clamp(0.0, 500.0)
: cacheExtent;
final firstVisibleRow = (scrollOffset / rowHeight).floor().clamp(0, rowCount);
final visibleRowCount = (viewportExtent / rowHeight).ceil() + 1;
final lastVisibleRow = (firstVisibleRow + visibleRowCount).clamp(0, rowCount);
final bufferRows = (effectiveCacheExtent / rowHeight).ceil();
return VisibleRowRange(
(firstVisibleRow - bufferRows).clamp(0, rowCount),
(lastVisibleRow + bufferRows).clamp(0, rowCount),
);
}