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
labelType: labelType,
iconTheme: widget.selectedIndex == i ? selectedIconTheme : unselectedIconTheme,
labelTextStyle: widget.selectedIndex == i ? selectedLabelTextStyle : unselectedLabelTextStyle,
padding: widget.destinations[i].padding,
onTap: () {
widget.onDestinationSelected!(i);
},
......@@ -579,6 +580,7 @@ class _RailDestination extends StatelessWidget {
required this.labelTextStyle,
required this.onTap,
required this.indexLabel,
this.padding,
}) : assert(minWidth != null),
assert(minExtendedWidth != null),
assert(icon != null),
......@@ -609,6 +611,7 @@ class _RailDestination extends StatelessWidget {
final TextStyle labelTextStyle;
final VoidCallback onTap;
final String indexLabel;
final EdgeInsetsGeometry? padding;
final Animation<double> _positionAnimation;
......@@ -634,7 +637,9 @@ class _RailDestination extends StatelessWidget {
),
);
if (extendedTransitionAnimation.value == 0) {
content = Stack(
content = Padding(
padding: padding ?? EdgeInsets.zero,
child: Stack(
children: <Widget>[
iconPart,
// For semantics when label is not showing,
......@@ -648,9 +653,12 @@ class _RailDestination extends StatelessWidget {
),
),
]
),
);
} else {
content = ConstrainedBox(
content = Padding(
padding: padding ?? EdgeInsets.zero,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: lerpDouble(minWidth, minExtendedWidth, extendedTransitionAnimation.value)!,
),
......@@ -672,6 +680,7 @@ class _RailDestination extends StatelessWidget {
],
),
),
),
);
}
break;
......@@ -683,7 +692,7 @@ class _RailDestination extends StatelessWidget {
minWidth: minWidth,
minHeight: minWidth,
),
padding: const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding),
padding: padding ?? const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding),
child: ClipRect(
child: Column(
mainAxisSize: MainAxisSize.min,
......@@ -713,7 +722,7 @@ class _RailDestination extends StatelessWidget {
minWidth: minWidth,
minHeight: minWidth,
),
padding: const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding),
padding: padding ?? const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding),
child: Column(
children: <Widget>[
const SizedBox(height: _verticalDestinationPaddingWithLabel),
......@@ -811,6 +820,7 @@ class NavigationRailDestination {
required this.icon,
Widget? selectedIcon,
this.label,
this.padding,
}) : selectedIcon = selectedIcon ?? icon,
assert(icon != null);
......@@ -848,6 +858,9 @@ class NavigationRailDestination {
/// still used for semantics, and may still be used if
/// [NavigationRail.extended] is true.
final Widget? label;
/// The amount of space to inset the destination item.
final EdgeInsetsGeometry? padding;
}
class _ExtendedNavigationRailAnimation extends InheritedWidget {
......
......@@ -2022,6 +2022,129 @@ void main() {
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() {
......
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