[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 | | --- | --- | |  |  |
This commit is contained in:
parent
04e284a49d
commit
91a84dedf5
@ -61,6 +61,7 @@ class NavigationDrawer extends StatelessWidget {
|
|||||||
this.indicatorShape,
|
this.indicatorShape,
|
||||||
this.onDestinationSelected,
|
this.onDestinationSelected,
|
||||||
this.selectedIndex = 0,
|
this.selectedIndex = 0,
|
||||||
|
this.tilePadding = const EdgeInsets.symmetric(horizontal: 12.0),
|
||||||
});
|
});
|
||||||
|
|
||||||
/// The background color of the [Material] that holds the [NavigationDrawer]'s
|
/// 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.
|
/// Upon updating [selectedIndex], the [NavigationDrawer] will be rebuilt.
|
||||||
final ValueChanged<int>? onDestinationSelected;
|
final ValueChanged<int>? onDestinationSelected;
|
||||||
|
|
||||||
|
/// Defines the padding for [NavigationDrawerDestination] widgets (Drawer items).
|
||||||
|
///
|
||||||
|
/// Defaults to `EdgeInsets.symmetric(horizontal: 12.0)`.
|
||||||
|
final EdgeInsetsGeometry tilePadding;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final int totalNumberOfDestinations =
|
final int totalNumberOfDestinations =
|
||||||
@ -141,6 +147,7 @@ class NavigationDrawer extends StatelessWidget {
|
|||||||
selectedAnimation: animation,
|
selectedAnimation: animation,
|
||||||
indicatorColor: indicatorColor,
|
indicatorColor: indicatorColor,
|
||||||
indicatorShape: indicatorShape,
|
indicatorShape: indicatorShape,
|
||||||
|
tilePadding: tilePadding,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (onDestinationSelected != null) {
|
if (onDestinationSelected != null) {
|
||||||
onDestinationSelected!(index);
|
onDestinationSelected!(index);
|
||||||
@ -321,7 +328,7 @@ class _NavigationDestinationBuilder extends StatelessWidget {
|
|||||||
final NavigationDrawerThemeData defaults = _NavigationDrawerDefaultsM3(context);
|
final NavigationDrawerThemeData defaults = _NavigationDrawerDefaultsM3(context);
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
padding: info.tilePadding,
|
||||||
child: _NavigationDestinationSemantics(
|
child: _NavigationDestinationSemantics(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: navigationDrawerTheme.tileHeight ?? defaults.tileHeight,
|
height: navigationDrawerTheme.tileHeight ?? defaults.tileHeight,
|
||||||
@ -455,6 +462,7 @@ class _NavigationDrawerDestinationInfo extends InheritedWidget {
|
|||||||
required this.indicatorShape,
|
required this.indicatorShape,
|
||||||
required this.onTap,
|
required this.onTap,
|
||||||
required super.child,
|
required super.child,
|
||||||
|
required this.tilePadding,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Which destination index is this in the navigation drawer.
|
/// Which destination index is this in the navigation drawer.
|
||||||
@ -514,6 +522,11 @@ class _NavigationDrawerDestinationInfo extends InheritedWidget {
|
|||||||
/// with [index] passed in.
|
/// with [index] passed in.
|
||||||
final VoidCallback onTap;
|
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].
|
/// Returns a non null [_NavigationDrawerDestinationInfo].
|
||||||
///
|
///
|
||||||
/// This will return an error if called with no [_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.
|
// Test that InkWell for hover, focus and pressed use custom shape.
|
||||||
expect(_getInkWell(tester)?.customBorder, 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) {
|
Widget _buildWidget(GlobalKey<ScaffoldState> scaffoldKey, Widget child) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user