vertical_tabs
vertical_tabs copied to clipboard
Cannot change the number of tabs at runtime
I have a filter widget on the screen that indicates if part of the tabs or all the tabs are visible in the VisibleTabs widget. The default value is part of the tabs (part.length < all.length). When I change the filter at runtime with setState the tabs property is changed with a larger list and all the tabs should be visible but instead I get an error: RangeError (index): Invalid value: Not in range 0..6, inclusive: 7
The problem is in the animationControllers list that is initialized only in the initState method so any change to the tabs list length doesn't change the animationControllers list length. The part in the build method that throws the error is: new CurvedAnimation( parent: animationControllers[index], curve: Curves.elasticOut, ),
If you need more info let me know.
I resolved my problem by implementing a method that does a reset of the animationControllers list when the filter value is changed but you can implement it in a more clean way without external interaction :)
Flutter doctor: [√] Flutter (Channel dev, 1.19.0-1.0.pre, on Microsoft Windows [Version 10.0.14393], locale hr-HR) [√] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [√] Android Studio (version 3.6)
@wolfcro1984 Hi! I have the same problem,How to fix this? thanks :)
I fixed it in an ugly way but if you want you can do the same. This is my implementation. VerticalTabs.dart.txt
The important thing is to reset the tabs in the onChanged handler outside the VerticalTabs widget.
onChanged: (bool state) { setState(() { _tabsKey.currentState.disposeAnimationControllers(); }); },
@wolfcro1984 thanks.