[Material] Fix BottomNavTheme.showSelectedLabels bug#67342
[Material] Fix BottomNavTheme.showSelectedLabels bug#67342fluttergithubbot merged 10 commits intoflutter:masterfrom
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.
Should _defaultShowUnselected just be replaced with the value itself to match the line above?
There was a problem hiding this comment.
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.
whats the reason for this change?
There was a problem hiding this comment.
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.
This isn't strictly true (it defaults to null) and it doesn't cover what's actually happening: widget.showSelectedLabels ?? bottomTheme.showSelectedLabels ?? true.
| /// | ||
| /// 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.
Similar comment to the previous one.
| final double unselectedIconSize = unselectedIconTheme?.size | ||
| ?? bottomTheme.unselectedIconTheme?.size | ||
| ?? iconSize; | ||
| final double selectedIconSize = selectedIconTheme?.size ?? iconSize; |
There was a problem hiding this comment.
Why are we now ignoring bottomTheme.selectedIconTheme?.size? Here and on the next line.
There was a problem hiding this comment.
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.
| /// 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.
typo here - remove trailing argument defaults to true`.
There was a problem hiding this comment.
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.
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.