revealOffsetsFor method
The scroll offsets that would bring a cell fully into view, or null for an axis that already shows it.
Lives here because it is the only place that knows both the row geometry and how much of the width the pinned bands have already taken — scrolling a cell into view behind a pinned column is the bug this exists to avoid.
Implementation
(double? vertical, double? horizontal) revealOffsetsFor(
int row,
int column, {
double padding = 0.0,
}) {
double? dy;
if (row >= 0 && row < rowCount) {
final top = _rowMetrics.offsetOf(row);
final bottom = top + _rowMetrics.heightOf(row);
if (top - padding < _verticalOffset) {
dy = math.max(0.0, top - padding);
} else if (bottom + padding > _verticalOffset + size.height) {
dy = math.min(
math.max(0.0, contentHeight - size.height),
bottom + padding - size.height,
);
}
}
double? dx;
final layout = _columnLayout;
if (column >= 0 && column < layout.length && layout.scrolls(column)) {
// Measured from the leading edge of the scrolling band, not the viewport,
// so a pinned column never gets to hide the cell we just scrolled to.
final bandStart = layout.offsets[layout.leadingFrozenCount];
final start = layout.offsets[column] - bandStart;
final end = start + layout.widths[column];
if (start - padding < _horizontalOffset) {
dx = math.max(0.0, start - padding);
} else if (end + padding > _horizontalOffset + _scrollableExtent) {
dx = math.min(maxHorizontalOffset, end + padding - _scrollableExtent);
}
}
return (dy, dx);
}