NavigationRail constructor Null safety

const NavigationRail(
  1. {Key? key,
  2. Color? backgroundColor,
  3. bool extended = false,
  4. Widget? leading,
  5. Widget? trailing,
  6. required List<NavigationRailDestination> destinations,
  7. required int? selectedIndex,
  8. ValueChanged<int>? onDestinationSelected,
  9. double? elevation,
  10. double? groupAlignment,
  11. NavigationRailLabelType? labelType,
  12. TextStyle? unselectedLabelTextStyle,
  13. TextStyle? selectedLabelTextStyle,
  14. IconThemeData? unselectedIconTheme,
  15. IconThemeData? selectedIconTheme,
  16. double? minWidth,
  17. double? minExtendedWidth,
  18. bool? useIndicator,
  19. Color? indicatorColor}
)

Creates a Material Design navigation rail.

The value of destinations must be a list of two or more NavigationRailDestination values.

If elevation is specified, it must be non-negative.

If minWidth is specified, it must be non-negative, and if minExtendedWidth is specified, it must be non-negative and greater than minWidth.

The argument extended must not be null. extended can only be set to true when the labelType is null or NavigationRailLabelType.none.

If backgroundColor, elevation, groupAlignment, labelType, unselectedLabelTextStyle, selectedLabelTextStyle, unselectedIconTheme, or selectedIconTheme are null, then their NavigationRailThemeData values will be used. If the corresponding NavigationRailThemeData property is null, then the navigation rail defaults are used. See the individual properties for more information.

Typically used within a Row that defines the Scaffold.body property.

Implementation

const NavigationRail({
  super.key,
  this.backgroundColor,
  this.extended = false,
  this.leading,
  this.trailing,
  required this.destinations,
  required this.selectedIndex,
  this.onDestinationSelected,
  this.elevation,
  this.groupAlignment,
  this.labelType,
  this.unselectedLabelTextStyle,
  this.selectedLabelTextStyle,
  this.unselectedIconTheme,
  this.selectedIconTheme,
  this.minWidth,
  this.minExtendedWidth,
  this.useIndicator,
  this.indicatorColor,
}) :  assert(destinations != null && destinations.length >= 2),
      assert(selectedIndex == null || (0 <= selectedIndex && selectedIndex < destinations.length)),
      assert(elevation == null || elevation > 0),
      assert(minWidth == null || minWidth > 0),
      assert(minExtendedWidth == null || minExtendedWidth > 0),
      assert((minWidth == null || minExtendedWidth == null) || minExtendedWidth >= minWidth),
      assert(extended != null),
      assert(!extended || (labelType == null || labelType == NavigationRailLabelType.none));