standardNavigationRail static method

Builder standardNavigationRail({
  1. required List<NavigationRailDestination> destinations,
  2. double width = 72,
  3. int? selectedIndex,
  4. bool extended = false,
  5. Color? backgroundColor,
  6. EdgeInsetsGeometry padding = const EdgeInsets.all(8.0),
  7. Widget? leading,
  8. Widget? trailing,
  9. void onDestinationSelected(
    1. int
    )?,
  10. double? groupAlignment,
  11. IconThemeData? selectedIconTheme,
  12. IconThemeData? unselectedIconTheme,
  13. TextStyle? selectedLabelTextStyle,
  14. TextStyle? unSelectedLabelTextStyle,
  15. NavigationRailLabelType labelType = NavigationRailLabelType.none,
})

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,
                  ),
                ),
              ),
            );
          },
        ),
      ),
    );
  });
}