refactor: share low-risk UI and tracker helpers
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user