visibleRowIndices property

List<int> get visibleRowIndices

Indices of complete rows intersecting the current vertical viewport. Includes partially visible rows and is independent of horizontal scrolling. Read after row insertion/extent animations have settled.

Already expressed in logical space, so it needs no zoom adjustment: it reads the scroll position's viewport dimension, which zooming shrinks or grows, and reports exactly the rows on screen — a zoomed-in sheet simply has fewer of them.

Implementation

List<int> get visibleRowIndices {
  final controller = _verticalIndexedController.controller;
  if (!controller.hasClients) return const [];
  final start = controller.offset;
  final end = start + controller.position.viewportDimension;
  if (end <= start) return const [];
  var top = 0.0;
  final indices = <int>[];
  for (var row = 0; row < widget.rowCount; row++) {
    final bottom = top + _rowHeightAt(row);
    if (bottom > start && top < end) indices.add(row);
    if (top >= end) break;
    top = bottom;
  }
  return indices;
}