Skip to content

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

Merged
auto-submit[bot] merged 2 commits into
flutter:mainfrom
Massinissa-Mouhoub:port-189157
Oct 6, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:mainfrom
Massinissa-Mouhoub:port-189157

Conversation

@Massinissa-Mouhoub

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

Copy link
Copy Markdown
Contributor

This is the port of this PR after decoupling.

Fixes flutter/flutter#188837.

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!

@Massinissa-Mouhoub

Copy link
Copy Markdown
Contributor Author

@dkwingsmt Any thoughts on this PR ?

@Massinissa-Mouhoub

Copy link
Copy Markdown
Contributor Author

Hello mate @dkwingsmt do you mind checking this PR please?

@dkwingsmt dkwingsmt 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, and sorry for the late review!

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 6, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 6, 2026
@QuncCccccc QuncCccccc added the CICD Run CI/CD label Oct 6, 2026
@auto-submit
auto-submit Bot merged commit 149be41 into flutter:main Oct 6, 2026
13 checks passed
Mairramer pushed a commit to Mairramer/flutter that referenced this pull request Oct 8, 2026
flutter/packages@7660d46...54706bd

2026-10-08 [email protected] [image_picker_ios] Return an error
for undecodable image data (flutter/packages#12267)
2026-10-07 [email protected] [flutter shaders] update min flutter
version (flutter/packages#13160)
2026-10-07 [email protected] Import flutter_shaders package
(flutter/packages#12583)
2026-10-07 [email protected]
[material_ui] Migrate M3 Typography template to use new gen_defaults
(flutter/packages#13074)
2026-10-07 [email protected] Sync release-material_ui-1.6.0 to
main (flutter/packages#13149)
2026-10-07 [email protected] [pigeon] Fix native interop (JNI) calls
in minified Android release builds (flutter/packages#13151)
2026-10-06 [email protected] [material_ui] Migrate
ListTile and SwitchListTile API doc snippets to {@example} (batch 10)
(flutter/packages#13097)
2026-10-06 [email protected] Sync release-cupertino_ui-1.1.2 to
main (flutter/packages#13150)
2026-10-06 [email protected]
[material_ui] Fix `TabBar` assertion to allow `indicatorWeight: 0` with
a themed `indicator` (flutter/packages#12696)
2026-10-06 [email protected] [material_ui] Fix time picker input
validation for 24-hour locales (flutter/packages#13033)
2026-10-06 [email protected] [material_ui] Migrate
Checkbox, CheckboxListTile, Radio, and RadioListTile API doc snippets to
{@example} (batch 9) (flutter/packages#13112)
2026-10-06 [email protected] [quick_actions_android] Return null from
getLaunchAction when no activity is attached (flutter/packages#12331)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
flutter/packages@7660d46...54706bd

2026-10-08 [email protected] [image_picker_ios] Return an error
for undecodable image data (flutter/packages#12267)
2026-10-07 [email protected] [flutter shaders] update min flutter
version (flutter/packages#13160)
2026-10-07 [email protected] Import flutter_shaders package
(flutter/packages#12583)
2026-10-07 [email protected]
[material_ui] Migrate M3 Typography template to use new gen_defaults
(flutter/packages#13074)
2026-10-07 [email protected] Sync release-material_ui-1.6.0 to
main (flutter/packages#13149)
2026-10-07 [email protected] [pigeon] Fix native interop (JNI) calls
in minified Android release builds (flutter/packages#13151)
2026-10-06 [email protected] [material_ui] Migrate
ListTile and SwitchListTile API doc snippets to {@example} (batch 10)
(flutter/packages#13097)
2026-10-06 [email protected] Sync release-cupertino_ui-1.1.2 to
main (flutter/packages#13150)
2026-10-06 [email protected]
[material_ui] Fix `TabBar` assertion to allow `indicatorWeight: 0` with
a themed `indicator` (flutter/packages#12696)
2026-10-06 [email protected] [material_ui] Fix time picker input
validation for 24-hour locales (flutter/packages#13033)
2026-10-06 [email protected] [material_ui] Migrate
Checkbox, CheckboxListTile, Radio, and RadioListTile API doc snippets to
{@example} (batch 9) (flutter/packages#13112)
2026-10-06 [email protected] [quick_actions_android] Return null from
getLaunchAction when no activity is attached (flutter/packages#12331)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App 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

3 participants