Skip to content

Conversation

chinmoy12c
Copy link
Member

@chinmoy12c chinmoy12c commented Oct 30, 2020

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:

  • verticalSpacing properly applied
  • itemSpacing properly applied
  • itemSpacing overrides verticalSpacing
  • Extra SizedBox not added when verticalSpacing and itemSpacing are not set

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.

  • No, no existing tests failed, so this is not a breaking change.

@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 30, 2020
@google-cla google-cla bot added the cla: yes label Oct 30, 2020
@chinmoy12c chinmoy12c force-pushed the issue_69193 branch 3 times, most recently from 20d3f13 to 5e13453 Compare October 30, 2020 15:24
@HansMuller HansMuller requested a review from clocksmith November 5, 2020 19:22
@flutter-dashboard
Copy link

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 package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@christopherfujino
Copy link
Contributor

@clocksmith can you take a look at this?

Comment on lines 771 to 774
if (verticalSpacing != 0 || itemSpacing != 0)
SizedBox(
height: itemSpacing != 0 ? itemSpacing : verticalSpacing,
),
Copy link
Contributor

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.

Copy link
Member Author

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.

@chinmoy12c chinmoy12c force-pushed the issue_69193 branch 2 times, most recently from 30d2cfe to 73df9d3 Compare December 28, 2020 10:36
@@ -609,6 +611,7 @@ class _RailDestination extends StatelessWidget {
final TextStyle labelTextStyle;
final VoidCallback onTap;
final String indexLabel;
final double padding;
Copy link
Contributor

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.

Copy link
Member Author

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

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.

Copy link
Contributor

@shihaohong shihaohong Dec 29, 2020

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
}

Copy link
Member Author

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 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
}

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.

Copy link
Contributor

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!

@chinmoy12c
Copy link
Member Author

@shihaohong I've updated the PR. Please do tell if any changes are required regarding the tappable area wrapping padding.

Happy new year 🎉🎉

@chinmoy12c chinmoy12c requested a review from shihaohong January 6, 2021 13:17
@shihaohong shihaohong changed the title Added verticalSpacing and itemSpacing property in NavigationRail Added padding property in NavigationRail Jan 7, 2021
await _pumpNavigationRail(
tester,
navigationRail: NavigationRail(
labelType: NavigationRailLabelType.all,
Copy link
Contributor

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.

Copy link
Member Author

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);.

Copy link
Contributor

@shihaohong shihaohong left a 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.

Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

[NavigationRail] Ability to add vertical space between icons
4 participants