File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ class _ChipTabSwitcherState extends State<ChipTabSwitcher> {
106106 TabController ? _tabController;
107107 Animation <double >? _tabAnimation;
108108 int _activeIndex = 0 ;
109+ int _scrollRequestEpoch = 0 ;
109110 late List <GlobalKey > _tabKeys;
110111
111112 @override
@@ -198,10 +199,14 @@ class _ChipTabSwitcherState extends State<ChipTabSwitcher> {
198199 return 0 ;
199200 }
200201
202+ final maxIndex = widget.tabs.length - 1 ;
203+ if (controller.indexIsChanging) {
204+ return controller.index.clamp (0 , maxIndex);
205+ }
206+
201207 final animationValue =
202208 controller.animation? .value ?? controller.index.toDouble ();
203- final roundedIndex = animationValue.round ();
204- return roundedIndex.clamp (0 , widget.tabs.length - 1 );
209+ return animationValue.round ().clamp (0 , maxIndex);
205210 }
206211
207212 void _handleChipTap (int index) {
@@ -219,7 +224,11 @@ class _ChipTabSwitcherState extends State<ChipTabSwitcher> {
219224 }
220225
221226 void _scrollTabIntoView (int index, {bool animate = true }) {
227+ final requestEpoch = ++ _scrollRequestEpoch;
222228 WidgetsBinding .instance.addPostFrameCallback ((_) {
229+ if (requestEpoch != _scrollRequestEpoch) {
230+ return ;
231+ }
223232 if (! mounted || index < 0 || index >= _tabKeys.length) {
224233 return ;
225234 }
You can’t perform that action at this time.
0 commit comments