Unverified Commit 91a84ded authored by Tirth's avatar Tirth Committed by GitHub

[NavigationDrawer] adds padding property in NavigationDrawer Widget (#123961)

Adds `tilePadding` property to `NavigationDrawer` Widget.

Fixes: #121662

| Without adding `tilePadding` in NavigationDrawer | With `tilePadding: EdgeInsets.all(16)` in NavigationDrawer |
| --- | --- |
| ![photo_2023-04-02_15-03-56](https://user-images.githubusercontent.com/13456345/229344718-9070c0c0-9c71-4436-9953-d258367951e9.jpg) | ![photo_2023-04-02_15-04-00](https://user-images.githubusercontent.com/13456345/229344717-0768f9d5-6a55-4c2f-918e-53f2423bb959.jpg) |
parent 04e284a4
......@@ -61,6 +61,7 @@ class NavigationDrawer extends StatelessWidget {
this.indicatorShape,
this.onDestinationSelected,
this.selectedIndex = 0,
this.tilePadding = const EdgeInsets.symmetric(horizontal: 12.0),
});
/// The background color of the [Material] that holds the [NavigationDrawer]'s
......@@ -124,6 +125,11 @@ class NavigationDrawer extends StatelessWidget {
/// Upon updating [selectedIndex], the [NavigationDrawer] will be rebuilt.
final ValueChanged<int>? onDestinationSelected;
/// Defines the padding for [NavigationDrawerDestination] widgets (Drawer items).
///
/// Defaults to `EdgeInsets.symmetric(horizontal: 12.0)`.
final EdgeInsetsGeometry tilePadding;
@override
Widget build(BuildContext context) {
final int totalNumberOfDestinations =
......@@ -141,6 +147,7 @@ class NavigationDrawer extends StatelessWidget {
selectedAnimation: animation,
indicatorColor: indicatorColor,
indicatorShape: indicatorShape,
tilePadding: tilePadding,
onTap: () {
if (onDestinationSelected != null) {
onDestinationSelected!(index);
......@@ -321,7 +328,7 @@ class _NavigationDestinationBuilder extends StatelessWidget {
final NavigationDrawerThemeData defaults = _NavigationDrawerDefaultsM3(context);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
padding: info.tilePadding,
child: _NavigationDestinationSemantics(
child: SizedBox(
height: navigationDrawerTheme.tileHeight ?? defaults.tileHeight,
......@@ -455,6 +462,7 @@ class _NavigationDrawerDestinationInfo extends InheritedWidget {
required this.indicatorShape,
required this.onTap,
required super.child,
required this.tilePadding,
});
/// Which destination index is this in the navigation drawer.
......@@ -514,6 +522,11 @@ class _NavigationDrawerDestinationInfo extends InheritedWidget {
/// with [index] passed in.
final VoidCallback onTap;
/// Defines the padding for [NavigationDrawerDestination] widgets (Drawer items).
///
/// Defaults to `EdgeInsets.symmetric(horizontal: 12.0)`.
final EdgeInsetsGeometry tilePadding;
/// Returns a non null [_NavigationDrawerDestinationInfo].
///
/// This will return an error if called with no [_NavigationDrawerDestinationInfo]
......
......@@ -360,6 +360,29 @@ void main() {
// Test that InkWell for hover, focus and pressed use custom shape.
expect(_getInkWell(tester)?.customBorder, shape);
});
testWidgets('NavigationDrawer.tilePadding defaults to EdgeInsets.symmetric(horizontal: 12.0)', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
widgetSetup(tester, 3000, viewHeight: 3000);
final Widget widget = _buildWidget(
scaffoldKey,
NavigationDrawer(
children: const <Widget>[
NavigationDrawerDestination(
icon: Icon(Icons.ac_unit),
label: Text('AC'),
),
],
onDestinationSelected: (int i) {},
),
);
await tester.pumpWidget(widget);
scaffoldKey.currentState?.openDrawer();
await tester.pump();
final NavigationDrawer drawer = tester.widget(find.byType(NavigationDrawer));
expect(drawer.tilePadding, const EdgeInsets.symmetric(horizontal: 12.0));
});
}
Widget _buildWidget(GlobalKey<ScaffoldState> scaffoldKey, Widget child) {
......
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