[material_ui] Port flutter/flutter #189157 "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"
This is the port of this PR after decoupling.
Fixes this.
Pre-Review Checklist
[shared_preferences]///).