@@ -24,6 +24,13 @@ const double kMaterialMediumMinMargin = 12;
2424/// design 3 spec.
2525const double kMaterialExpandedMinMargin = 32 ;
2626
27+ /// Signature for a builder used by [AdaptiveScaffold.navigationRailDestinationBuilder] that converts a
28+ /// [NavigationDestination] to a [NavigationRailDestination] .
29+ typedef NavigationRailDestinationBuilder = NavigationRailDestination Function (
30+ int index,
31+ NavigationDestination destination,
32+ );
33+
2734/// Implements the basic visual layout structure for
2835/// [Material Design 3] (https://m3.material.io/foundations/adaptive-design/overview)
2936/// that adapts to a variety of screens.
@@ -103,6 +110,8 @@ class AdaptiveScaffold extends StatefulWidget {
103110 this .navigationRailWidth = 72 ,
104111 this .extendedNavigationRailWidth = 192 ,
105112 this .appBarBreakpoint,
113+ this .navigationRailDestinationBuilder,
114+ this .groupAlignment,
106115 }) : assert (
107116 destinations.length >= 2 ,
108117 'At least two destinations are required' ,
@@ -129,6 +138,9 @@ class AdaptiveScaffold extends StatefulWidget {
129138 /// navigation rail at the largest breakpoint.
130139 final Widget ? trailingNavRail;
131140
141+ /// The alignment of the destinations in the navigation rail.
142+ final double ? groupAlignment;
143+
132144 /// Widget to be displayed in the body slot at the smallest breakpoint.
133145 ///
134146 /// If nothing is entered for this property, then the default [body] is
@@ -246,6 +258,9 @@ class AdaptiveScaffold extends StatefulWidget {
246258 /// [Breakpoint] .
247259 final double extendedNavigationRailWidth;
248260
261+ /// Used to map NavigationDestination to NavigationRailDestination.
262+ final NavigationRailDestinationBuilder ? navigationRailDestinationBuilder;
263+
249264 /// Callback function for when the index of a [NavigationRail] changes.
250265 static WidgetBuilder emptyBuilder = (_) => const SizedBox ();
251266
@@ -267,6 +282,9 @@ class AdaptiveScaffold extends StatefulWidget {
267282 /// Takes in a [selectedIndex] property for the current selected item in
268283 /// the [NavigationRail] and [extended] for whether the [NavigationRail]
269284 /// is extended or not.
285+ ///
286+ /// If [labelType] is null, then the default value is
287+ /// [NavigationRailLabelType.none] .
270288 static Builder standardNavigationRail ({
271289 required List <NavigationRailDestination > destinations,
272290 double width = 72 ,
@@ -282,7 +300,7 @@ class AdaptiveScaffold extends StatefulWidget {
282300 IconThemeData ? unselectedIconTheme,
283301 TextStyle ? selectedLabelTextStyle,
284302 TextStyle ? unSelectedLabelTextStyle,
285- NavigationRailLabelType labelType = NavigationRailLabelType .none,
303+ NavigationRailLabelType ? labelType = NavigationRailLabelType .none,
286304 }) {
287305 if (extended && width == 72 ) {
288306 width = 192 ;
@@ -513,6 +531,13 @@ class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
513531 final NavigationRailThemeData navRailTheme =
514532 Theme .of (context).navigationRailTheme;
515533
534+ final List <NavigationRailDestination > destinations = widget.destinations
535+ .map ((NavigationDestination destination) =>
536+ widget.navigationRailDestinationBuilder
537+ ? .call (widget.destinations.indexOf (destination), destination) ??
538+ AdaptiveScaffold .toRailDestination (destination))
539+ .toList ();
540+
516541 return Scaffold (
517542 key: _scaffoldKey,
518543 appBar: widget.drawerBreakpoint.isActive (context) && widget.useDrawer ||
@@ -526,11 +551,15 @@ class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
526551 leading: widget.leadingExtendedNavRail,
527552 trailing: widget.trailingNavRail,
528553 selectedIndex: widget.selectedIndex,
529- destinations: widget.destinations
530- .map ((NavigationDestination destination) =>
531- AdaptiveScaffold .toRailDestination (destination))
532- .toList (),
554+ destinations: destinations,
533555 onDestinationSelected: _onDrawerDestinationSelected,
556+ backgroundColor: navRailTheme.backgroundColor,
557+ selectedIconTheme: navRailTheme.selectedIconTheme,
558+ unselectedIconTheme: navRailTheme.unselectedIconTheme,
559+ selectedLabelTextStyle: navRailTheme.selectedLabelTextStyle,
560+ unselectedLabelTextStyle: navRailTheme.unselectedLabelTextStyle,
561+ groupAlignment: widget.groupAlignment,
562+ labelType: navRailTheme.labelType,
534563 ),
535564 )
536565 : null ,
@@ -548,16 +577,15 @@ class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
548577 leading: widget.leadingUnextendedNavRail,
549578 trailing: widget.trailingNavRail,
550579 selectedIndex: widget.selectedIndex,
551- destinations: widget.destinations
552- .map ((NavigationDestination destination) =>
553- AdaptiveScaffold .toRailDestination (destination))
554- .toList (),
580+ destinations: destinations,
555581 onDestinationSelected: widget.onSelectedIndexChange,
556582 backgroundColor: navRailTheme.backgroundColor,
557583 selectedIconTheme: navRailTheme.selectedIconTheme,
558584 unselectedIconTheme: navRailTheme.unselectedIconTheme,
559585 selectedLabelTextStyle: navRailTheme.selectedLabelTextStyle,
560586 unSelectedLabelTextStyle: navRailTheme.unselectedLabelTextStyle,
587+ labelType: navRailTheme.labelType,
588+ groupAlignment: widget.groupAlignment,
561589 ),
562590 ),
563591 widget.largeBreakpoint: SlotLayout .from (
@@ -568,16 +596,15 @@ class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
568596 leading: widget.leadingExtendedNavRail,
569597 trailing: widget.trailingNavRail,
570598 selectedIndex: widget.selectedIndex,
571- destinations: widget.destinations
572- .map ((NavigationDestination destination) =>
573- AdaptiveScaffold .toRailDestination (destination))
574- .toList (),
599+ destinations: destinations,
575600 onDestinationSelected: widget.onSelectedIndexChange,
576601 backgroundColor: navRailTheme.backgroundColor,
577602 selectedIconTheme: navRailTheme.selectedIconTheme,
578603 unselectedIconTheme: navRailTheme.unselectedIconTheme,
579604 selectedLabelTextStyle: navRailTheme.selectedLabelTextStyle,
580605 unSelectedLabelTextStyle: navRailTheme.unselectedLabelTextStyle,
606+ labelType: navRailTheme.labelType,
607+ groupAlignment: widget.groupAlignment,
581608 ),
582609 ),
583610 },
0 commit comments