standardNavigationRail static method
Creates a Material 3 Design Spec abiding NavigationRail from a list of NavigationDestinations.
Takes in a selectedIndex
property for the current selected item in
the NavigationRail and extended
for whether the NavigationRail
is extended or not.
Implementation
static Builder standardNavigationRail({
required List<NavigationRailDestination> destinations,
double width = 72,
int? selectedIndex,
bool extended = false,
Color? backgroundColor,
EdgeInsetsGeometry padding = const EdgeInsets.all(8.0),
Widget? leading,
Widget? trailing,
void Function(int)? onDestinationSelected,
double? groupAlignment,
IconThemeData? selectedIconTheme,
IconThemeData? unselectedIconTheme,
TextStyle? selectedLabelTextStyle,
TextStyle? unSelectedLabelTextStyle,
NavigationRailLabelType labelType = NavigationRailLabelType.none,
}) {
if (extended && width == 72) {
width = 192;
}
return Builder(builder: (BuildContext context) {
return Padding(
padding: padding,
child: SizedBox(
width: width,
height: MediaQuery.of(context).size.height,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: constraints.maxHeight),
child: IntrinsicHeight(
child: NavigationRail(
labelType: labelType,
leading: leading,
trailing: trailing,
onDestinationSelected: onDestinationSelected,
groupAlignment: groupAlignment,
backgroundColor: backgroundColor,
extended: extended,
selectedIndex: selectedIndex,
selectedIconTheme: selectedIconTheme,
unselectedIconTheme: unselectedIconTheme,
selectedLabelTextStyle: selectedLabelTextStyle,
unselectedLabelTextStyle: unSelectedLabelTextStyle,
destinations: destinations,
),
),
),
);
},
),
),
);
});
}