-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[Material] Expand BottomNavigationBar API #27698
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
Conversation
86389b8 to
6f012c1
Compare
…tter into feature-newBottomNavBarApi
…ure-newBottomNavBarApi
…ure-newBottomNavBarApi
rami-a
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
| /// [BottomNavigationBar]s. If [selectedItemColor] and [fixedColor] are | ||
| /// null, then the theme's primary color, [ThemeData.primaryColor] is used. | ||
| /// | ||
| /// [iconSize] must be at least 8.0 for the [Icon]s to display properly. |
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 do they need to be 8?
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.
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.
Let Hans decide.
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 should figure out the reason and include it in the documentation.
BTW, nit: see https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-correct-grammar (avoid starting sentences with a lower case letter)
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 iconSize >= 8 is just a feature (ha) of the gallery demo: https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/material/bottom_navigation_demo.dart#L82
There's no need to constrain the iconSize parameter.
|
I would prefer the approach of having a flag (from #22956) over setting font size to zero |
| /// of different types. | ||
| final BottomNavigationBarType type; | ||
|
|
||
| /// Deprecated, use [selectedItemColor]. |
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 is this deprecated?
I'm confused about the relationship between fixedColor, selectedItemColor, and ThemeData.primaryColor. If fixedColor is set, that is selected over selectedItemColor. If fixedColor is unset, than ThemeData.primaryColor is used?
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.
So, fixedColor used to determine the color of the selected items, but only in Fixed BottomNavBars. In the case of Shifting, the selected items were always white.
I'm updating this behavior so that you can customize the selected item color for both Fixed and Shifting bottom nav bars.
My options were:
- Have
fixedColorapply to bothFixedandShiftingbottom nav bars. - Rename
fixedColortoselectedItemColor<-- breaking change - Create a new field called
selectedItemColorand "deprecate"fixedColorsince the name no longer makes sense.
So, I opted for the 3rd, but for backwards compatibility sake I made it so that if you don't supply selectedItemColor but you do supply a fixedColor, fixedColor will still be used.
Then it's a question of the defaults if neither parameter is provided. Again to keep this backwards compatible, I kept the behavior as is. That means that Shifting nav bars have a default selected item color of Colors.White, and Fixed bottom nav bars have a default selected item color of ThemeData.primaryColor.
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.
I don't think we should just comment on it as being deprecated unless we actually plan to remove it.
cc @Hixie @matthew-carroll @goderbauer
From #27753
It seems like this API is quite working as expected here. Do we take this as an opportunity to clean it up?
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.
Edit: is NOT quite working as expected
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.
I agree with Jonah here. There's a cost to having both colours now: the cognitive overhead of the API being more complicated, but also 8+ bytes per widget to store this field that we don't want people to use.
If you really wanted to keep it and not go through the deprecation process, you could have the constructor argument still exist and just have both it and selectedItemColor set the same field, and have the fixedColor field just return the same value.
But beyond that, we shouldn't say something is deprecated unless it's @deprecated and going to be removed.
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.
Good point, if we do want to deprecate, I should have used @deprecated. I'm fine either way, would people prefer to officially deprecate or leave both fixedColor and selectedItemColor?
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.
I think we should do any deprecations and removals outside of this PR to make it easier to land. I'm not sure what our policy is for the deprecated annotation, but an reasonable process might be:
- Land this PR with fixedColor pointing to selectedColor (and maybe an assert if you assign both).
- A breaking change request asking flutter dev about removing fixed color.
- At some later point in time, removing fixedColor in a separate PR
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.
Sounds good, I will follow the steps that Jonah laid out. Thanks for the input everyone.
Co-Authored-By: johnsonmh <johnsonmh@users.noreply.github.com>
Co-Authored-By: johnsonmh <johnsonmh@users.noreply.github.com>
…tter into feature-newBottomNavBarApi
| /// The color of the [BottomNavigationBar] itself. | ||
| /// | ||
| /// If [type] is [BottomNavigationBarType.shifting] and the | ||
| /// [items]s, have [BottomNavigationBarItem.backgroundColor] set, the [item]'s |
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.
[items]s, => [item]s
I think we get carried away with the links sometimes (they make the text a little harder to read). This could just be "items".
| /// [BottomNavigationBar]s. If [selectedItemColor] and [fixedColor] are | ||
| /// null, then the theme's primary color, [ThemeData.primaryColor] is used. | ||
| /// | ||
| /// [iconSize] must be at least 8.0 for the [Icon]s to display properly. |
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 iconSize >= 8 is just a feature (ha) of the gallery demo: https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/material/bottom_navigation_demo.dart#L82
There's no need to constrain the iconSize parameter.
|
I've moved the changes from this PR to: #28159. Will try and land that one soon, maybe today. |
Co-authored-by: MH Johnson <johnsonmh@google.com> Co-authored-by: Hyo Chan Jang <dooboolab@gmail.com>
Co-authored-by: masashi-sutou <sutou.masasi@gmail.com>

Expand the BottomNavigationBar API.
Add the ability to customize the following fields on
BottomNavigationBars:backgroundColorelevationselectedItemColorunselectedItemColorselectedFontSizeunSelectedFontSizeshowSelectedLabelsshowUnselectedLabelsCombining these fields allows users to create
BottomNavigationBars that match the current Material Design specifications, as well as support other requested features.The default behavior of BottomNavigationBar is still the same:
FixedShiftingCustom font size
Using custom
selectedFontSizeandunselectedFontSize, theBottomNavigationBarnow still animates properly.FixedShiftingCustom Coloring
Using custom
backgroundColor,selectedItemColor, andunselectedItemColor, theBottomNavigationBarcan be customized.Note: shifting
BottomNavigationBars respect the color of theirBottomNavigationBarItems rather than use theBottomNavigationBar'sbackgroundColor, this preserves the "ripple" behavior.FixedShiftingHide/Show labels
Being able to optionally hide/show selected and unselected labels on
fixedBottomNavigationBars allows us to get behavior described in the Material spec.showSelectedLabels && showUnselectedLabelsshowSelectedLabels && !showUnselectedLabels!showSelectedLabels && !showUnselectedLabelsCloses #23178
Closes #27414
Closes #17099
Closes #25895
Closes #22882
Closes #27739
Closes #27651