Repository navigation
[material_ui] Fix TabBar assertion to allow indicatorWeight: 0 with a themed indicator - #12696
Conversation
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)) {| 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.', | ||
| ), |
There was a problem hiding this comment.
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.',
),TabBar assertion to allow indicatorWeight: 0 with a themed indicator"
TabBar assertion to allow indicatorWeight: 0 with a themed indicator"TabBar assertion to allow indicatorWeight: 0 with a themed indicator
QuncCccccc
left a comment
There was a problem hiding this comment.
LGTM. Thank you for porting it over!
|
@dkwingsmt Any thoughts on this PR ? |
|
Hello mate @dkwingsmt do you mind checking this PR please? |
dkwingsmt
left a comment
There was a problem hiding this comment.
LGTM. Thank you, and sorry for the late review!
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
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
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
[shared_preferences]///).