-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Added padding property in NavigationRail #69404
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
20d3f13
to
5e13453
Compare
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
5e13453
to
484eed7
Compare
@clocksmith can you take a look at this? |
484eed7
to
bf69cdf
Compare
bf69cdf
to
7e8eccd
Compare
if (verticalSpacing != 0 || itemSpacing != 0) | ||
SizedBox( | ||
height: itemSpacing != 0 ? itemSpacing : verticalSpacing, | ||
), |
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 this has the right effect. For example, in the example app in the api docs (https://master-api.flutter.dev/flutter/material/NavigationRail-class.html), you will not see any difference until you have a itemSpacing or verticalSpacing value greater than ~70-80 because this just overlays the SizedBox on top of each item/icon in the navigation rail.
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.
Yes that's true. I guess this issue would no longer exist after making the suggested implementation of wrapping items in Padding widget.
30d2cfe
to
73df9d3
Compare
@@ -609,6 +611,7 @@ class _RailDestination extends StatelessWidget { | |||
final TextStyle labelTextStyle; | |||
final VoidCallback onTap; | |||
final String indexLabel; | |||
final double padding; |
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 not just be an EdgeInsetsGeometry
, similar to Containers? This would make the padding property more flexible and consistent with how padding is defined elsewhere.
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.
Yes, I'll change it to accept EdgeInsetsGeometry
👍
splashColor: colors.primary.withOpacity(0.12), | ||
hoverColor: colors.primary.withOpacity(0.04), | ||
child: content, | ||
child: Padding( |
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.
Also, did we discuss whether we want the padding to be surrounding the tappable InkResponse? I'm not sure what is the most useful behavior here, but we should verify whether to have Padding wrap InkResponse or vice versa.
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.
Another optimization that can be made here is that when padding is EdgeInsets.zero
or null
, to completely omit including the Padding widget in the widget tree altogether. Something similar to:
if (padding != null || padding != EdgeInsets.zero) {
child = Padding(padding: padding, child: child);
} else {
// What's there before
}
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.
Also, did we discuss whether we want the padding to be surrounding the tappable InkResponse? I'm not sure what is the most useful behavior here, but we should verify whether to have Padding wrap InkResponse or vice versa.
@shihaohong surrounding with tappable InkResponse would work, although I was thinking of a use case where the user might just want spacing between two items (like 100 or so), would it be okay to have such a long tappable area?
Another optimization that can be made here is that when padding is
EdgeInsets.zero
ornull
, to completely omit including the Padding widget in the widget tree altogether. Something similar to:if (padding != null || padding != EdgeInsets.zero) { child = Padding(padding: padding, child: child); } else { // What's there before }
Sure, I'll make the changes :) 👍
Also, should I add a test to check that the padding is not added in case of EdgeInsets.zero
.
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.
Yes, that's a good test to add!
73df9d3
to
5d75c8c
Compare
@shihaohong I've updated the PR. Please do tell if any changes are required regarding the tappable area wrapping padding. Happy new year 🎉🎉 |
5d75c8c
to
71e079e
Compare
71e079e
to
81f8082
Compare
81f8082
to
71a3a0f
Compare
await _pumpNavigationRail( | ||
tester, | ||
navigationRail: NavigationRail( | ||
labelType: NavigationRailLabelType.all, |
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.
Could you also add a test for NavigationRailLabelType.selected and NavigationRailLabelType.none?
Might also be worth adding a test for NavigationRailLabelType.all
and NavigationRailLabelType.selected
making sure that the default padding is applied (const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding
) when padding is not defined.
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.
Yeah sure I'll add a test for NavigationRailLabelType.selected and NavigationRailLabelType.none. Also, in the added test the first destination item uses default padding so it's checking for the default padding const EdgeInsets defaultPadding = EdgeInsets.symmetric(horizontal: 8.0);
.
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.
Very close, thanks for these updates. Just needs a few more tests to make sure the behavior is as expected and that no regressions occur.
71a3a0f
to
270c40b
Compare
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
Description
Adds verticalSpacing and itemSpacing property in NavigationRail to provide the ability to add custom spacing between NavigationRailDestination items.
Related Issues
Fixes #69193
Tests
I added the following tests:
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.