improved support for disable animations

This commit is contained in:
Fabian Freund
2026-03-12 03:37:59 +01:00
parent e001701b07
commit 57a8b2f013
14 changed files with 224 additions and 110 deletions
+15 -7
View File
@@ -24,14 +24,19 @@ void useSyncPageWithTab(
TabController tabController,
PageController pageController, {
void Function(int index)? onIndexChanged,
bool disableAnimations = false,
}) {
useEffect(() {
Future<void> syncPage() async {
await pageController.animateToPage(
tabController.index,
curve: Curves.linear,
duration: const Duration(milliseconds: 300),
);
if (disableAnimations) {
pageController.jumpToPage(tabController.index);
} else {
await pageController.animateToPage(
tabController.index,
curve: Curves.linear,
duration: const Duration(milliseconds: 300),
);
}
onIndexChanged?.call(tabController.index);
}
@@ -39,7 +44,10 @@ void useSyncPageWithTab(
if (!tabController.indexIsChanging) {
final index = pageController.page!.round();
tabController.animateTo(index);
tabController.animateTo(
index,
duration: disableAnimations ? Duration.zero : kTabScrollDuration,
);
onIndexChanged?.call(index);
}
}
@@ -51,5 +59,5 @@ void useSyncPageWithTab(
tabController.removeListener(syncPage);
pageController.removeListener(syncTab);
};
}, [tabController, pageController]);
}, [tabController, pageController, disableAnimations]);
}