Unverified Commit 76d41143 authored by Chinmoy's avatar Chinmoy Committed by GitHub

Added padding property to NavigationRail items (#69404)

parent c89d6498
...@@ -496,6 +496,7 @@ class _NavigationRailState extends State<NavigationRail> with TickerProviderStat ...@@ -496,6 +496,7 @@ class _NavigationRailState extends State<NavigationRail> with TickerProviderStat
labelType: labelType, labelType: labelType,
iconTheme: widget.selectedIndex == i ? selectedIconTheme : unselectedIconTheme, iconTheme: widget.selectedIndex == i ? selectedIconTheme : unselectedIconTheme,
labelTextStyle: widget.selectedIndex == i ? selectedLabelTextStyle : unselectedLabelTextStyle, labelTextStyle: widget.selectedIndex == i ? selectedLabelTextStyle : unselectedLabelTextStyle,
padding: widget.destinations[i].padding,
onTap: () { onTap: () {
widget.onDestinationSelected!(i); widget.onDestinationSelected!(i);
}, },
...@@ -579,6 +580,7 @@ class _RailDestination extends StatelessWidget { ...@@ -579,6 +580,7 @@ class _RailDestination extends StatelessWidget {
required this.labelTextStyle, required this.labelTextStyle,
required this.onTap, required this.onTap,
required this.indexLabel, required this.indexLabel,
this.padding,
}) : assert(minWidth != null), }) : assert(minWidth != null),
assert(minExtendedWidth != null), assert(minExtendedWidth != null),
assert(icon != null), assert(icon != null),
...@@ -609,6 +611,7 @@ class _RailDestination extends StatelessWidget { ...@@ -609,6 +611,7 @@ class _RailDestination extends StatelessWidget {
final TextStyle labelTextStyle; final TextStyle labelTextStyle;
final VoidCallback onTap; final VoidCallback onTap;
final String indexLabel; final String indexLabel;
final EdgeInsetsGeometry? padding;
final Animation<double> _positionAnimation; final Animation<double> _positionAnimation;
...@@ -634,7 +637,9 @@ class _RailDestination extends StatelessWidget { ...@@ -634,7 +637,9 @@ class _RailDestination extends StatelessWidget {
), ),
); );
if (extendedTransitionAnimation.value == 0) { if (extendedTransitionAnimation.value == 0) {
content = Stack( content = Padding(
padding: padding ?? EdgeInsets.zero,
child: Stack(
children: <Widget>[ children: <Widget>[
iconPart, iconPart,
// For semantics when label is not showing, // For semantics when label is not showing,
...@@ -648,9 +653,12 @@ class _RailDestination extends StatelessWidget { ...@@ -648,9 +653,12 @@ class _RailDestination extends StatelessWidget {
), ),
), ),
] ]
),
); );
} else { } else {
content = ConstrainedBox( content = Padding(
padding: padding ?? EdgeInsets.zero,
child: ConstrainedBox(
constraints: BoxConstraints( constraints: BoxConstraints(
minWidth: lerpDouble(minWidth, minExtendedWidth, extendedTransitionAnimation.value)!, minWidth: lerpDouble(minWidth, minExtendedWidth, extendedTransitionAnimation.value)!,
), ),
...@@ -672,6 +680,7 @@ class _RailDestination extends StatelessWidget { ...@@ -672,6 +680,7 @@ class _RailDestination extends StatelessWidget {
], ],
), ),
), ),
),
); );
} }
break; break;
...@@ -683,7 +692,7 @@ class _RailDestination extends StatelessWidget { ...@@ -683,7 +692,7 @@ class _RailDestination extends StatelessWidget {
minWidth: minWidth, minWidth: minWidth,
minHeight: minWidth, minHeight: minWidth,
), ),
padding: const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding), padding: padding ?? const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding),
child: ClipRect( child: ClipRect(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
...@@ -713,7 +722,7 @@ class _RailDestination extends StatelessWidget { ...@@ -713,7 +722,7 @@ class _RailDestination extends StatelessWidget {
minWidth: minWidth, minWidth: minWidth,
minHeight: minWidth, minHeight: minWidth,
), ),
padding: const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding), padding: padding ?? const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
const SizedBox(height: _verticalDestinationPaddingWithLabel), const SizedBox(height: _verticalDestinationPaddingWithLabel),
...@@ -811,6 +820,7 @@ class NavigationRailDestination { ...@@ -811,6 +820,7 @@ class NavigationRailDestination {
required this.icon, required this.icon,
Widget? selectedIcon, Widget? selectedIcon,
this.label, this.label,
this.padding,
}) : selectedIcon = selectedIcon ?? icon, }) : selectedIcon = selectedIcon ?? icon,
assert(icon != null); assert(icon != null);
...@@ -848,6 +858,9 @@ class NavigationRailDestination { ...@@ -848,6 +858,9 @@ class NavigationRailDestination {
/// still used for semantics, and may still be used if /// still used for semantics, and may still be used if
/// [NavigationRail.extended] is true. /// [NavigationRail.extended] is true.
final Widget? label; final Widget? label;
/// The amount of space to inset the destination item.
final EdgeInsetsGeometry? padding;
} }
class _ExtendedNavigationRailAnimation extends InheritedWidget { class _ExtendedNavigationRailAnimation extends InheritedWidget {
......
...@@ -2022,6 +2022,129 @@ void main() { ...@@ -2022,6 +2022,129 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('NavigationRailDestination padding properly applied - NavigationRailLabelType.all', (WidgetTester tester) async {
const EdgeInsets defaultPadding = EdgeInsets.symmetric(horizontal: 8.0);
const EdgeInsets secondItemPadding = EdgeInsets.symmetric(vertical: 30.0);
const EdgeInsets thirdItemPadding = EdgeInsets.symmetric(horizontal: 10.0);
await _pumpNavigationRail(
tester,
navigationRail: NavigationRail(
labelType: NavigationRailLabelType.all,
selectedIndex: 0,
destinations: const <NavigationRailDestination>[
NavigationRailDestination(
icon: Icon(Icons.favorite_border),
selectedIcon: Icon(Icons.favorite),
label: Text('Abc'),
),
NavigationRailDestination(
icon: Icon(Icons.bookmark_border),
selectedIcon: Icon(Icons.bookmark),
label: Text('Def'),
padding: secondItemPadding,
),
NavigationRailDestination(
icon: Icon(Icons.star_border),
selectedIcon: Icon(Icons.star),
label: Text('Ghi'),
padding: thirdItemPadding,
),
],
),
);
final Padding firstItem = tester.widget<Padding>(find.widgetWithText(Padding, 'Abc'));
final Padding secondItem = tester.widget<Padding>(find.widgetWithText(Padding, 'Def'));
final Padding thirdItem = tester.widget<Padding>(find.widgetWithText(Padding, 'Ghi'));
expect(firstItem.padding, defaultPadding);
expect(secondItem.padding, secondItemPadding);
expect(thirdItem.padding, thirdItemPadding);
});
testWidgets('NavigationRailDestination padding properly applied - NavigationRailLabelType.selected', (WidgetTester tester) async {
const EdgeInsets defaultPadding = EdgeInsets.symmetric(horizontal: 8.0);
const EdgeInsets secondItemPadding = EdgeInsets.symmetric(vertical: 30.0);
const EdgeInsets thirdItemPadding = EdgeInsets.symmetric(horizontal: 10.0);
await _pumpNavigationRail(
tester,
navigationRail: NavigationRail(
labelType: NavigationRailLabelType.selected,
selectedIndex: 0,
destinations: const <NavigationRailDestination>[
NavigationRailDestination(
icon: Icon(Icons.favorite_border),
selectedIcon: Icon(Icons.favorite),
label: Text('Abc'),
),
NavigationRailDestination(
icon: Icon(Icons.bookmark_border),
selectedIcon: Icon(Icons.bookmark),
label: Text('Def'),
padding: secondItemPadding,
),
NavigationRailDestination(
icon: Icon(Icons.star_border),
selectedIcon: Icon(Icons.star),
label: Text('Ghi'),
padding: thirdItemPadding,
),
],
),
);
final Padding firstItem = tester.widget<Padding>(find.widgetWithText(Padding, 'Abc'));
final Padding secondItem = tester.widget<Padding>(find.widgetWithText(Padding, 'Def'));
final Padding thirdItem = tester.widget<Padding>(find.widgetWithText(Padding, 'Ghi'));
expect(firstItem.padding, defaultPadding);
expect(secondItem.padding, secondItemPadding);
expect(thirdItem.padding, thirdItemPadding);
});
testWidgets('NavigationRailDestination padding properly applied - NavigationRailLabelType.none', (WidgetTester tester) async {
const EdgeInsets defaultPadding = EdgeInsets.zero;
const EdgeInsets secondItemPadding = EdgeInsets.symmetric(vertical: 30.0);
const EdgeInsets thirdItemPadding = EdgeInsets.symmetric(horizontal: 10.0);
await _pumpNavigationRail(
tester,
navigationRail: NavigationRail(
labelType: NavigationRailLabelType.none,
selectedIndex: 0,
destinations: const <NavigationRailDestination>[
NavigationRailDestination(
icon: Icon(Icons.favorite_border),
selectedIcon: Icon(Icons.favorite),
label: Text('Abc'),
),
NavigationRailDestination(
icon: Icon(Icons.bookmark_border),
selectedIcon: Icon(Icons.bookmark),
label: Text('Def'),
padding: secondItemPadding,
),
NavigationRailDestination(
icon: Icon(Icons.star_border),
selectedIcon: Icon(Icons.star),
label: Text('Ghi'),
padding: thirdItemPadding,
),
],
),
);
final Padding firstItem = tester.widget<Padding>(find.widgetWithText(Padding, 'Abc'));
final Padding secondItem = tester.widget<Padding>(find.widgetWithText(Padding, 'Def'));
final Padding thirdItem = tester.widget<Padding>(find.widgetWithText(Padding, 'Ghi'));
expect(firstItem.padding, defaultPadding);
expect(secondItem.padding, secondItemPadding);
expect(thirdItem.padding, thirdItemPadding);
});
} }
TestSemantics _expectedSemantics() { TestSemantics _expectedSemantics() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment