fix tab sheet scroll logic

This commit is contained in:
Fabian Freund
2025-08-11 09:14:45 +02:00
parent c45a87609a
commit f7db231eb7
@@ -456,38 +456,36 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
); );
final lastScroll = useRef<String?>(null); final lastScroll = useRef<String?>(null);
final scrollControllerIsAttached = useListenableSelector(
sheetScrollController,
() => sheetScrollController.hasClients,
);
useEffect(() { useEffect(() {
if (scrollControllerIsAttached) { WidgetsBinding.instance.addPostFrameCallback((_) {
if (lastScroll.value != activeTab) { if (sheetScrollController.hasClients) {
final index = filteredTabEntities.value.indexWhere( if (lastScroll.value != activeTab) {
(entity) => entity.tabId == activeTab, final index = filteredTabEntities.value.indexWhere(
); (entity) => entity.tabId == activeTab,
);
if (index > -1) { if (index > -1) {
final offset = (index ~/ 2) * itemHeight; final offset = (index ~/ 2) * itemHeight;
if (offset != sheetScrollController.offset) { if (offset != sheetScrollController.offset) {
lastScroll.value = activeTab; lastScroll.value = activeTab;
unawaited( unawaited(
sheetScrollController.animateTo( sheetScrollController.animateTo(
offset, offset,
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut, curve: Curves.easeInOut,
), ),
); );
}
} }
} }
} }
} });
return null; return null;
}, [filteredTabEntities, activeTab, scrollControllerIsAttached]); }, [filteredTabEntities, activeTab]);
final tabs = useMemoized(() { final tabs = useMemoized(() {
return [ return [