NavigationRail constructor

const NavigationRail({
  1. Key? key,
  2. Color? backgroundColor,
  3. NavigationRailAlignment alignment = NavigationRailAlignment.center,
  4. Axis direction = Axis.vertical,
  5. double? spacing,
  6. NavigationLabelType labelType = NavigationLabelType.selected,
  7. NavigationLabelPosition labelPosition = NavigationLabelPosition.bottom,
  8. NavigationLabelSize labelSize = NavigationLabelSize.small,
  9. EdgeInsetsGeometry? padding,
  10. BoxConstraints? constraints,
  11. int? index,
  12. ValueChanged<int>? onSelected,
  13. double? surfaceOpacity,
  14. double? surfaceBlur,
  15. bool expanded = true,
  16. bool keepMainAxisSize = false,
  17. bool keepCrossAxisSize = false,
  18. required List<NavigationBarItem> children,
})

Creates a NavigationRail with the specified configuration and items.

The children parameter is required and should contain NavigationBarItem widgets that define the navigation destinations. Other parameters control the rail's appearance, behavior, and layout characteristics.

Default values provide a sensible vertical rail configuration suitable for most sidebar navigation scenarios. Customization allows adaptation to specific layout requirements and design systems.

Parameters:

  • children (List
  • alignment (NavigationRailAlignment, default: center): Item alignment along main axis
  • direction (Axis, default: vertical): Layout orientation of the rail
  • labelType (NavigationLabelType, default: selected): When to show labels
  • labelPosition (NavigationLabelPosition, default: bottom): Label positioning
  • index (int?, optional): Currently selected item index
  • onSelected (ValueChanged

Example:

NavigationRail(
  alignment: NavigationRailAlignment.start,
  labelType: NavigationLabelType.all,
  index: currentIndex,
  onSelected: (index) => _navigate(index),
  children: navigationItems,
)

Implementation

const NavigationRail({
  super.key,
  this.backgroundColor,
  this.alignment = NavigationRailAlignment.center,
  this.direction = Axis.vertical,
  this.spacing,
  this.labelType = NavigationLabelType.selected,
  this.labelPosition = NavigationLabelPosition.bottom,
  this.labelSize = NavigationLabelSize.small,
  this.padding,
  this.constraints,
  this.index,
  this.onSelected,
  this.surfaceOpacity,
  this.surfaceBlur,
  this.expanded = true,
  this.keepMainAxisSize = false,
  this.keepCrossAxisSize = false,
  required this.children,
});