Skip to content

Conversation

@johnsonmh
Copy link
Contributor

@johnsonmh johnsonmh commented Oct 5, 2020

Description

This PR fixes a bug with the BottomNavigationBarThemeData.showSelectedLabels param. Because BottomNavigationBar.showSelectedLables was being set to true, 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:

  • Test that BottomNavTheme.showSelectedLabels: false and BottomNavTheme.showUnselectedLabels: false works when no widget params provided.
  • Test that BottomNavTheme.showSelectedLabels: false and BottomNavTheme.showUnselectedLabels: true works when no widget params provided.
  • Test that BottomNavTheme.showSelectedLabels: true and BottomNavTheme.showUnselectedLabels: false works 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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Oct 5, 2020
selected: i == widget.currentIndex,
showSelectedLabels: widget.showSelectedLabels ?? bottomTheme.showSelectedLabels,
showSelectedLabels: widget.showSelectedLabels ?? bottomTheme.showSelectedLabels ?? true,
showUnselectedLabels: widget.showUnselectedLabels ?? bottomTheme.showUnselectedLabels ?? _defaultShowUnselected,
Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines 477 to 487
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,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

#67078

/// The [showSelectedLabels] argument must be non-null.
///
/// The [showUnselectedLabels] argument defaults to `true` if [type] is
/// The [showSelectedLabels] argument defaults to `true`. The
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@HansMuller HansMuller left a 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`.
Copy link
Contributor

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`.

Copy link
Contributor Author

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,
Copy link
Contributor

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"

@pedromassangocode
Copy link

Updating PR to close the related issues automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[doc] BottomNavigationBarItem : Update title with label to reflect correct message. showSelectedLabels of BottomNavigationBarThemeData is not applied

7 participants