refactor: share low-risk UI and tracker helpers

This commit is contained in:
edde746
2026-05-02 01:58:50 +02:00
parent 646832c6b1
commit 50bc245677
18 changed files with 270 additions and 265 deletions
+15
View File
@@ -35,6 +35,21 @@ void scrollToCurrentItem(ScrollController controller, GlobalKey firstItemKey, in
});
}
/// Owns the boilerplate for one-time initial scrolling in selectable lists.
class InitialItemScrollController {
final GlobalKey firstItemKey = GlobalKey();
final ScrollController controller = ScrollController();
bool _didInitialScroll = false;
void maybeScrollTo(int? selectedIndex) {
if (_didInitialScroll || selectedIndex == null || selectedIndex <= 0) return;
_didInitialScroll = true;
scrollToCurrentItem(controller, firstItemKey, selectedIndex);
}
void dispose() => controller.dispose();
}
/// Scroll a horizontal list to center the item at the given index.
///
/// Assumes items are laid out with [leadingPadding] before the first item,