revealListRow function

Future<void> revealListRow(
  1. DevToolsFind find,
  2. ScrollController controller, {
  3. required int index,
  4. required int count,
})

A lazy list can't jump to a row it hasn't laid out, so this homes in over a few frames until the row's FindText has built and revealed itself.

Implementation

Future<void> revealListRow(
  DevToolsFind find,
  ScrollController controller, {
  required int index,
  required int count,
}) async {
  final version = find.revealVersion;
  for (var attempt = 0; attempt < 8; attempt++) {
    await SchedulerBinding.instance.endOfFrame;
    if (!find.revealPending || find.revealVersion != version) return;
    if (!controller.hasClients || count == 0) return;
    final position = controller.position;
    final extent = position.maxScrollExtent + position.viewportDimension;
    final estimate = extent * index / count - position.viewportDimension / 2;
    position.jumpTo(
      estimate.clamp(position.minScrollExtent, position.maxScrollExtent),
    );
  }
}