scrollOffsetToReveal static method
Compute the scroll offset needed to reveal the selected item in a fixed-height list.
Returns null if the item is already visible. The caller should
call scrollController.jumpTo(offset) with the returned value.
This is a pure calculation with no Flutter dependency.
Implementation
static double? scrollOffsetToReveal({
required int selectedIndex,
required double itemHeight,
required double viewportHeight,
required double currentOffset,
}) {
final target = selectedIndex * itemHeight;
if (target < currentOffset) {
return target;
}
if (target + itemHeight > currentOffset + viewportHeight) {
return target + itemHeight - viewportHeight;
}
return null;
}