Skip to content

[material_ui] Fix TabBar assertion to allow indicatorWeight: 0 with a themed indicator - #12696

Open
Massinissa-Mouhoub wants to merge 1 commit into
flutter:mainfrom
Massinissa-Mouhoub:port-189157
Open

[material_ui] Fix TabBar assertion to allow indicatorWeight: 0 with a themed indicator#12696
Massinissa-Mouhoub wants to merge 1 commit into
flutter:mainfrom
Massinissa-Mouhoub:port-189157

Conversation

@Massinissa-Mouhoub

@Massinissa-Mouhoub Massinissa-Mouhoub commented Aug 30, 2026

Copy link
Copy Markdown

This is the port of this PR after decoupling.

Fixes this.

Original PR Description

This PR moves the assertion that checks indicator != null || (indicatorWeight > 0.0) from the TabBar constructors into the Decoration _getIndicator(TabBarIndicatorSize indicatorSize) method. During the first phase of creating the TabBar widget, Dart just fills in the fields, there is no BuildContext available yet, so the widget has no way of access the TabBarTheme via context.dependOnInheritedWidgetOfExactType(). As a result, the constructor's assertion can only see the indicator passed directly to the widget, and it fails even when a valid indicator is supplied through the TabBarTheme.

By moving the assertion into the method mentionned above, which runs at build time, the TabBar now has access to the TabBarTheme and can validate the indicator correctly, accepting indicatorWeight: 0 when a themed indicator is present, while still asserting when the default underline indicator is used.

Fixes flutter/flutter#188837

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • All existing and new tests are passing.

@github-actions github-actions Bot added p: material_ui triage-design Should be looked at in design triage labels Aug 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request allows TabBar to accept an indicatorWeight of 0.0 when a custom indicator is supplied by the widget or TabBarThemeData. It removes the constructor-level assertions and introduces a runtime assertion with a detailed FlutterError when the default underline indicator is drawn with an invalid weight. Additionally, tests are added to verify these behaviors. The review feedback suggests improving the robustness of the weight check to handle NaN values and correcting a class reference in the error message for consistency.

return tabBarTheme.indicator!;
}
assert(() {
if (widget.indicatorWeight <= 0.0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using !(widget.indicatorWeight > 0.0) instead of widget.indicatorWeight <= 0.0 is more robust because it also correctly handles double.nan values, ensuring that any invalid weight triggers the assertion rather than potentially causing silent rendering issues or secondary errors later.

      if (!(widget.indicatorWeight > 0.0)) {

Comment on lines +1650 to +1654
ErrorDescription(
'The indicatorWeight must be greater than zero when the TabBar '
'draws its default underline indicator, that is when no indicator '
'is provided by the TabBar or the TabBarTheme.',
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the rest of the error message (such as the ErrorHint below and the documentation), refer to TabBarThemeData instead of TabBarTheme in the error description.

          ErrorDescription(
            'The indicatorWeight must be greater than zero when the TabBar '
            'draws its default underline indicator, that is when no indicator '
            'is provided by the TabBar or the TabBarThemeData.',
          ),

@Massinissa-Mouhoub Massinissa-Mouhoub changed the title fix: allow TabBar indicatorWeight of 0 with a themed indicator [material_ui] Port flutter/flutter #189157 "Fix TabBar assertion to allow indicatorWeight: 0 with a themed indicator" Aug 30, 2026
@elliette elliette changed the title [material_ui] Port flutter/flutter #189157 "Fix TabBar assertion to allow indicatorWeight: 0 with a themed indicator" [material_ui] Fix TabBar assertion to allow indicatorWeight: 0 with a themed indicator Sep 1, 2026
@QuncCccccc QuncCccccc added the CICD Run CI/CD label Sep 1, 2026

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for porting it over!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD p: material_ui triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TabBar throws assertion indicator != null || indicatorWeight > 0.0 despite a TabBarThemeData.indicator

2 participants