fix(tab): avoid TabController crash when all conditional tabs are hidden#2255
Closed
cursor[bot] wants to merge 1 commit into
Closed
fix(tab): avoid TabController crash when all conditional tabs are hidden#2255cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
When every tab has a conditional visible binding that evaluates to false, handleConditionalTabs() can leave zero visible items. TabController asserts length >= 1, which crashed the app during _reinitializeTabController. Use a placeholder length of 1 when no tabs are visible (build already returns shrink) and skip tab selection listeners until tabs return. Align ScrollableTabBar with the same guard and selectedIndex clamp. Co-authored-by: Sharjeel Yunus <sharjeelyunus@users.noreply.github.com>
This was referenced Jun 4, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Resubmits the fix from #2241 (closed without merge on 2026-06-01). When every tab in a
TabBarorScrollableTabBaruses a conditionalvisiblebinding and all bindings evaluate to false at runtime,handleConditionalTabs()leaves zero visible items and_reinitializeTabController()createdTabController(length: 0), which violates Flutter’slength >= 1assertion and crashes the app.Bug and impact
Trigger: A screen with tabs where each item has
visible: ${someCondition}, and runtime evaluation sets every condition to false (e.g. filter state hides all tabs).Impact: Framework assertion failure / app crash during tab controller reinitialization.
Root cause
updateVisibleItems()can produce an empty visible tab list, but_initializeTabController()passeditems.lengthdirectly toTabControllerwithout guarding zero.Fix
effectiveTabControllerLength()so controller length is never below 1 when no tabs are visible (UI already returnsSizedBox.shrink()whenitems.isEmpty).notifyListeneron the placeholder controller when there are no visible tabs.ScrollableTabBarand clampselectedIndexwhen reinitializing.Validation
modules/ensemble/test/effective_tab_controller_length_test.dart.flutter test test/effective_tab_controller_length_test.dartfrommodules/ensemble.Duplicate check
cursor/critical-bug-remediation-adc5): same root cause and fix; closed without merge; reopen was not permitted via API.TabController.cursor/critical-bug-remediation-adc5contains commit77dc95b1(cherry-picked here asb0c06eb6).