-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[Material] Fix BottomNavTheme.showSelectedLabels bug #67342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Material] Fix BottomNavTheme.showSelectedLabels bug #67342
Conversation
| selected: i == widget.currentIndex, | ||
| showSelectedLabels: widget.showSelectedLabels ?? bottomTheme.showSelectedLabels, | ||
| showSelectedLabels: widget.showSelectedLabels ?? bottomTheme.showSelectedLabels ?? true, | ||
| showUnselectedLabels: widget.showUnselectedLabels ?? bottomTheme.showUnselectedLabels ?? _defaultShowUnselected, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should _defaultShowUnselected just be replaced with the value itself to match the line above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because _defaultShowUnselected is a getter that depends on the BottomNavigationBar.type
| selectedIconTheme: selectedIconTheme, | ||
| unselectedIconTheme: unselectedIconTheme, | ||
| ), | ||
| _Label( | ||
| colorTween: colorTween, | ||
| animation: animation, | ||
| item: item, | ||
| selectedLabelStyle: selectedLabelStyle ?? bottomTheme.selectedLabelStyle, | ||
| unselectedLabelStyle: unselectedLabelStyle ?? bottomTheme.unselectedLabelStyle, | ||
| showSelectedLabels: showSelectedLabels ?? bottomTheme.showUnselectedLabels, | ||
| showUnselectedLabels: showUnselectedLabels ?? bottomTheme.showUnselectedLabels, | ||
| selectedLabelStyle: selectedLabelStyle, | ||
| unselectedLabelStyle: unselectedLabelStyle, | ||
| showSelectedLabels: showSelectedLabels, | ||
| showUnselectedLabels: showUnselectedLabels, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the reason for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null coalescing here is redundant, because the values passed to _BottomNavigationTile have already done the null theme checks. This will also make the NNBD migration more clear.
| /// The [showSelectedLabels] argument must be non-null. | ||
| /// | ||
| /// The [showUnselectedLabels] argument defaults to `true` if [type] is | ||
| /// The [showSelectedLabels] argument defaults to `true`. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't strictly true (it defaults to null) and it doesn't cover what's actually happening: widget.showSelectedLabels ?? bottomTheme.showSelectedLabels ?? true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated comment
| /// | ||
| /// The [showUnselectedLabels] argument defaults to `true` if [type] is | ||
| /// The [showSelectedLabels] argument defaults to `true`. The | ||
| /// [showUnselectedLabels] argument defaults to `true` if [type] is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment to the previous one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated comment
| final double unselectedIconSize = unselectedIconTheme?.size | ||
| ?? bottomTheme.unselectedIconTheme?.size | ||
| ?? iconSize; | ||
| final double selectedIconSize = selectedIconTheme?.size ?? iconSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we now ignoring bottomTheme.selectedIconTheme?.size? Here and on the next line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this offline, but to summarize, the whole BottomNavigationBarThemeData.selectedIconTheme is ignored if BottomNavigationBar.selectedIconTheme is present. I updated the documentation on BottomNavigationBarThemeData to make that more clear.
HansMuller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| /// The [showSelectedLabels] argument must be non-null. | ||
| /// If [showSelectedLabels] is `null`, [BottomNavigationBarThemeData.showSelectedLabels] | ||
| /// is used. If [BottomNavigationBarThemeData.showSelectedLabels] is null, | ||
| /// then [showSelectedLabels] defaults to `true`.argument defaults to `true`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here - remove trailing argument defaults to true`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting this
| /// The [showUnselectedLabels] argument defaults to `true` if [type] is | ||
| /// [BottomNavigationBarType.fixed] and `false` if [type] is | ||
| /// If [showUnselectedLabels] is `null`, [BottomNavigationBarThemeData.showUnselectedLabels] | ||
| /// is used. If [BottomNavigationBarThemeData.showSelectedLabels] is null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space before "is null"
|
Updating PR to close the related issues automatically. |
Description
This PR fixes a bug with the
BottomNavigationBarThemeData.showSelectedLabelsparam. BecauseBottomNavigationBar.showSelectedLableswas being set totrue, in the constructor, that meant it was not null by default, as the rest of the implementation expected.Also cleaned up some of the NNBD logic.
Related Issues
Fixes #66738
Fixes #67185
Tests
I added the following tests:
BottomNavTheme.showSelectedLabels: falseandBottomNavTheme.showUnselectedLabels: falseworks when no widget params provided.BottomNavTheme.showSelectedLabels: falseandBottomNavTheme.showUnselectedLabels: trueworks when no widget params provided.BottomNavTheme.showSelectedLabels: trueandBottomNavTheme.showUnselectedLabels: falseworks when no widget params provided.Checklist
Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.