verticalOffsetForFlattenChange static method
New vertical offset after an incremental single-node change, or null when the change happened at/below the viewport top (so nothing visible moves).
The offset moves by the change's row delta, clamped to the scroll end of
the new content: newContentHeight - viewportHeight.
Implementation
static double? verticalOffsetForFlattenChange({
required FlattenChange change,
required double currentOffset,
required double itemExtent,
required double topPadding,
required double newContentHeight,
required double viewportHeight,
}) {
final changePixel = topPadding + (change.index + 1) * itemExtent;
if (changePixel <= currentOffset) {
final delta = change.deltaItems * itemExtent;
final newMaxExtent = (newContentHeight - viewportHeight).clamp(
0.0,
double.infinity,
);
return (currentOffset + delta).clamp(0.0, newMaxExtent);
}
return null;
}