Skip to content

fix(tab): avoid TabController crash when all conditional tabs are hidden#2241

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-remediation-adc5
Draft

fix(tab): avoid TabController crash when all conditional tabs are hidden#2241
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-remediation-adc5

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor Bot commented May 28, 2026

Description

Fixes an app crash when every tab in a TabBar or ScrollableTabBar uses a conditional visible binding and all bindings evaluate to false at runtime.

Bug and impact

Trigger: A screen with tabs where each item has visible: ${someCondition} (or equivalent), and runtime evaluation sets every condition to false (e.g. user clears a filter that controlled all tab visibility).

Impact: handleConditionalTabs() calls _reinitializeTabController(), which created TabController(length: 0). Flutter asserts length >= 1, causing a framework assertion crash.

Root cause

updateVisibleItems() can produce an empty visible tab list, but _initializeTabController() passed items.length directly to TabController without guarding zero.

Fix

  • Introduce effectiveTabControllerLength() so controller length is never below 1 when no tabs are visible (UI already returns SizedBox.shrink()).
  • Skip notifyListener on the placeholder controller when there are no visible tabs.
  • Apply the same length guard to ScrollableTabBar and clamp selectedIndex when reinitializing (matching TabBar).

Validation

  • Added modules/ensemble/test/effective_tab_controller_length_test.dart.
  • Flutter SDK was not available on the automation image PATH; please run flutter test test/effective_tab_controller_length_test.dart from modules/ensemble per AGENTS.md.

Duplicate check

Open in Web View Automation 

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant