Skip to main content

NavigationRail

Struct NavigationRail 

Source
pub struct NavigationRail {
Show 24 fields pub key: Option<KeyRef>, pub background_color: Option<Color>, pub extended: bool, pub leading: Option<WidgetRef>, pub trailing: Option<WidgetRef>, pub destinations: Vec<NavigationRailDestination>, pub selected_index: Option<usize>, pub on_destination_selected: Option<ValueChanged<usize>>, pub elevation: Option<f64>, pub group_alignment: Option<f64>, pub label_type: Option<NavigationRailLabelType>, pub unselected_label_text_style: Option<TextStyle>, pub selected_label_text_style: Option<TextStyle>, pub unselected_icon_theme: Option<IconThemeData>, pub selected_icon_theme: Option<IconThemeData>, pub min_width: Option<f64>, pub min_extended_width: Option<f64>, pub use_indicator: Option<bool>, pub indicator_color: Option<Color>, pub indicator_shape: Option<ShapeBorderRef>, pub leading_at_top: bool, pub trailing_at_bottom: bool, pub scrollable: bool, pub main_axis_alignment: Option<MainAxisAlignment>,
}
Expand description

A Material Design widget that is meant to be displayed at the left or right of an app to navigate between a small number of views, typically between three and five.

Learn more about NavigationRail on the Flutter YouTube channel.

The navigation rail is meant for layouts with wide viewports, such as a desktop web or tablet landscape layout. For smaller layouts, like mobile portrait, a BottomNavigationBar should be used instead.

A navigation rail is usually used as the first or last element of a Row which defines the app’s Scaffold body.

The appearance of all of the NavigationRails within an app can be specified with NavigationRailTheme. The default values for null theme properties are based on the Theme’s ThemeData::text_theme, ThemeData::icon_theme, and ThemeData::color_scheme.

Adaptive layouts can build different instances of the Scaffold in order to have a navigation rail for more horizontal layouts and a bottom navigation bar for more vertical layouts. See the adaptive_scaffold.dart sample for an example.

See also:

Fields§

§key: Option<KeyRef>§background_color: Option<Color>

Sets the color of the Container that holds all of the NavigationRail’s contents.

The default value is NavigationRailThemeData::background_color. If NavigationRailThemeData::background_color is null, then the default value is based on ColorScheme::surface of ThemeData::color_scheme.

§extended: bool

Indicates that the NavigationRail should be in the extended state.

The extended state has a wider rail container, and the labels are positioned next to the icons. min_extended_width can be used to set the minimum width of the rail when it is in this state.

The rail will implicitly animate between the extended and normal state.

If the rail is going to be in the extended state, then the label_type must be set to NavigationRailLabelType::None.

The default value is false.

§leading: Option<WidgetRef>

The leading widget in the rail that is placed above the destinations.

It is placed at the top of the rail, above the destinations. Its location is not affected by group_alignment.

This is commonly a FloatingActionButton, but may also be a non-button, such as a logo.

The default value is null.

§trailing: Option<WidgetRef>

The trailing widget in the rail that is placed below the destinations.

The trailing widget is placed below the last NavigationRailDestination. It’s location is affected by group_alignment.

This is commonly a list of additional options or destinations that is usually only rendered when extended is true.

The default value is null.

§destinations: Vec<NavigationRailDestination>

Defines the appearance of the button items that are arrayed within the navigation rail.

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

§selected_index: Option<usize>

The index into destinations for the current selected NavigationRailDestination or null if no destination is selected.

§on_destination_selected: Option<ValueChanged<usize>>

Called when one of the destinations is selected.

The stateful widget that creates the navigation rail needs to keep track of the index of the selected NavigationRailDestination and call set_state to rebuild the navigation rail with the new selected_index.

§elevation: Option<f64>

The rail’s elevation or z-coordinate.

If Directionality is TextDirection::Ltr, the inner side is the right side, and if Directionality is TextDirection::Rtl, it is the left side.

The default value is 0.

§group_alignment: Option<f64>

The vertical alignment for the group of destinations within the rail.

The NavigationRailDestinations are by default grouped together with the trailing widget, due to trailing_at_bottom being false. The leading widget, can also be in the aligned group by setting leading_at_top to false. If these widgets are not included in the group, they are placed at the top and bottom, respectively, of the rail and only the space between them is considered for the alignment.

The value must be between -1.0 and 1.0.

If group_alignment is -1.0, then the items are aligned to the top. If group_alignment is 0.0, then the items are aligned to the center. If group_alignment is 1.0, then the items are aligned to the bottom.

The default is -1.0.

See also:

  • Alignment::y
§label_type: Option<NavigationRailLabelType>

Defines the layout and behavior of the labels for the default, unextended NavigationRail.

When a navigation rail is extended, the labels are always shown.

The default value is NavigationRailThemeData::label_type. If NavigationRailThemeData::label_type is null, then the default value is NavigationRailLabelType::None.

See also:

§unselected_label_text_style: Option<TextStyle>

The TextStyle of a destination’s label when it is unselected.

When one of the destinations is selected the selected_label_text_style will be used instead.

The default value is based on the Theme’s TextTheme::body_large. The default color is based on the Theme’s ColorScheme::on_surface.

Properties from this text style, or NavigationRailThemeData::unselected_label_text_style if this is null, are merged into the defaults.

§selected_label_text_style: Option<TextStyle>

The TextStyle of a destination’s label when it is selected.

When a NavigationRailDestination is not selected, unselected_label_text_style will be used.

The default value is based on the TextTheme::body_large of ThemeData::text_theme. The default color is based on the Theme’s ColorScheme::primary.

Properties from this text style, or NavigationRailThemeData::selected_label_text_style if this is null, are merged into the defaults.

§unselected_icon_theme: Option<IconThemeData>

The visual properties of the icon in the unselected destination.

If this field is not provided, or provided with any null properties, then a copy of the IconThemeData::fallback with a custom NavigationRail specific color will be used.

The default value is the Theme’s ThemeData::icon_theme with a color of the Theme’s ColorScheme::on_surface with an opacity of 0.64. Properties from this icon theme, or NavigationRailThemeData::unselected_icon_theme if this is null, are merged into the defaults.

§selected_icon_theme: Option<IconThemeData>

The visual properties of the icon in the selected destination.

When a NavigationRailDestination is not selected, unselected_icon_theme will be used.

The default value is the Theme’s ThemeData::icon_theme with a color of the Theme’s ColorScheme::primary. Properties from this icon theme, or NavigationRailThemeData::selected_icon_theme if this is null, are merged into the defaults.

§min_width: Option<f64>

The smallest possible width for the rail regardless of the destination’s icon or label size.

The default is 72.

This value also defines the min width and min height of the destinations.

To make a compact rail, set this to 56 and use NavigationRailLabelType::None.

§min_extended_width: Option<f64>

The final width when the animation is complete for setting extended to true.

This is only used when extended is set to true.

The default value is 256.

§use_indicator: Option<bool>

If true, adds a rounded NavigationIndicator behind the selected destination’s icon.

The indicator’s shape will be circular if label_type is NavigationRailLabelType::None, or a StadiumBorder if label_type is NavigationRailLabelType::All or NavigationRailLabelType::Selected.

If null, defaults to NavigationRailThemeData::use_indicator. If that is null, defaults to ThemeData::use_material3.

§indicator_color: Option<Color>

Overrides the default value of NavigationRail’s selection indicator color, when use_indicator is true.

If this is null, NavigationRailThemeData::indicator_color is used. If that is null, defaults to ColorScheme::secondary_container.

§indicator_shape: Option<ShapeBorderRef>

Overrides the default value of NavigationRail’s selection indicator shape, when use_indicator is true.

If this is null, NavigationRailThemeData::indicator_shape is used. If that is null, defaults to StadiumBorder.

§leading_at_top: bool

Pin the leading widget to the top.

If true, the leading widget is pinned to the top of the NavigationRail. Otherwise it precedes directly the main group of destinations.

See also scrollable for a description of the interplay of these parameters.

§trailing_at_bottom: bool

Pin the trailing widget to the bottom.

If true, the trailing widget is pinned to the bottom of the NavigationRail. Otherwise it follows directly the main group of destinations.

See also scrollable for a description of the interplay of these parameters.

§scrollable: bool

Whether the main group of items should be scrollable when vertical space is insufficient to show all of destinations, leading and trailing.

If leading_at_top or trailing_at_bottom are false, leading or trailing widgets, respectively, are part of the main group in addition to destinations. Otherwise these are statical at the top or bottom, respectively.

§main_axis_alignment: Option<MainAxisAlignment>

How the destinations should be placed along the vertical axis.

When there is extra vertical space in the NavigationRail, this property controls the alignment and spacing of the items. For example, setting this to MainAxisAlignment::SpaceEvenly will distribute the destinations equally along the available vertical space.

When this property is not null, group_alignment is ignored.

If null, the layout behaves as if MainAxisAlignment::Start was specified.

See also:

  • Column::main_axis_alignment, which describes the different values and their effects on the layout.

Implementations§

Source§

impl NavigationRail

Source

pub fn new( destinations: Vec<NavigationRailDestination>, selected_index: Option<usize>, ) -> NavigationRail

Creates a Material Design navigation rail.

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

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

If min_width is specified, it must be non-negative, and if min_extended_width is specified, it must be non-negative and greater than min_width.

The extended argument can only be set to true when the label_type is null or NavigationRailLabelType::None.

If background_color, elevation, group_alignment, label_type, unselected_label_text_style, selected_label_text_style, unselected_icon_theme, or selected_icon_theme 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.

Source

pub fn key(self, key: KeyRef) -> NavigationRail

Dart NavigationRail(key:).

Source

pub fn background_color(self, background_color: Color) -> NavigationRail

Dart NavigationRail(backgroundColor:).

Source

pub fn extended(self, extended: bool) -> NavigationRail

Dart NavigationRail(extended:).

Source

pub fn leading<K>(self, leading: impl IntoWidget<K>) -> NavigationRail

Dart NavigationRail(leading:).

Source

pub fn trailing<K>(self, trailing: impl IntoWidget<K>) -> NavigationRail

Dart NavigationRail(trailing:).

Source

pub fn on_destination_selected( self, on_destination_selected: impl Fn(&mut App, usize) + 'static, ) -> NavigationRail

Dart NavigationRail(onDestinationSelected:).

Source

pub fn elevation(self, elevation: f64) -> NavigationRail

Dart NavigationRail(elevation:).

Source

pub fn group_alignment(self, group_alignment: f64) -> NavigationRail

Dart NavigationRail(groupAlignment:).

Source

pub fn label_type(self, label_type: NavigationRailLabelType) -> NavigationRail

Dart NavigationRail(labelType:).

Source

pub fn unselected_label_text_style( self, unselected_label_text_style: TextStyle, ) -> NavigationRail

Dart NavigationRail(unselectedLabelTextStyle:).

Source

pub fn selected_label_text_style( self, selected_label_text_style: TextStyle, ) -> NavigationRail

Dart NavigationRail(selectedLabelTextStyle:).

Source

pub fn unselected_icon_theme( self, unselected_icon_theme: IconThemeData, ) -> NavigationRail

Dart NavigationRail(unselectedIconTheme:).

Source

pub fn selected_icon_theme( self, selected_icon_theme: IconThemeData, ) -> NavigationRail

Dart NavigationRail(selectedIconTheme:).

Source

pub fn min_width(self, min_width: f64) -> NavigationRail

Dart NavigationRail(minWidth:).

Source

pub fn min_extended_width(self, min_extended_width: f64) -> NavigationRail

Dart NavigationRail(minExtendedWidth:).

Source

pub fn use_indicator(self, use_indicator: bool) -> NavigationRail

Dart NavigationRail(useIndicator:).

Source

pub fn indicator_color(self, indicator_color: Color) -> NavigationRail

Dart NavigationRail(indicatorColor:).

Source

pub fn indicator_shape( self, indicator_shape: impl Into<ShapeBorderRef>, ) -> NavigationRail

Dart NavigationRail(indicatorShape:).

Source

pub fn leading_at_top(self, leading_at_top: bool) -> NavigationRail

Dart NavigationRail(leadingAtTop:).

Source

pub fn trailing_at_bottom(self, trailing_at_bottom: bool) -> NavigationRail

Dart NavigationRail(trailingAtBottom:).

Source

pub fn scrollable(self, scrollable: bool) -> NavigationRail

Dart NavigationRail(scrollable:).

Source

pub fn main_axis_alignment( self, main_axis_alignment: MainAxisAlignment, ) -> NavigationRail

Dart NavigationRail(mainAxisAlignment:).

Source

pub fn extended_animation( app: &mut App, context: BuildContext, ) -> AnyAnimation<f64>

Returns the animation that controls the NavigationRail::extended state.

This can be used to synchronize animations in the leading or trailing widget, such as an animated menu or a FloatingActionButton animation.

Trait Implementations§

Source§

impl Debug for NavigationRail

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for NavigationRail

Source§

type State = NavigationRailState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_check_constructor(&self)

Source§

fn create_state(&self) -> NavigationRailState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for NavigationRail

§

impl !Send for NavigationRail

§

impl !Sync for NavigationRail

§

impl !UnwindSafe for NavigationRail

§

impl Forget for NavigationRail

§

impl Freeze for NavigationRail
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const u8 is !null: Freeze, PhantomData<NavigationRailDestination>: Freeze, *const RcInner<dyn Fn(&mut App, usize)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, usize)>>: Freeze, &'static dyn ColorExtension: Freeze, *const RcInner<dyn ColorExtension> is !null: Freeze, PhantomData<RcInner<dyn ColorExtension>>: Freeze, PhantomData<u8>: Freeze, PhantomData<String>: Freeze, *const RcInner<Paint> is !null: Freeze, PhantomData<RcInner<Paint>>: Freeze, PhantomData<Shadow>: Freeze, PhantomData<FontFeature>: Freeze, PhantomData<FontVariation>: Freeze, *const RcInner<dyn Fn(&IconThemeData, &mut App, AnyElement) -> IconThemeData> is !null: Freeze, PhantomData<RcInner<dyn Fn(&IconThemeData, &mut App, AnyElement) -> IconThemeData>>: Freeze, *const RcInner<dyn ShapeBorder> is !null: Freeze, PhantomData<RcInner<dyn ShapeBorder>>: Freeze,

§

impl Move for NavigationRail

§

impl Unpin for NavigationRail
where Rc<dyn Key>: Unpin, Rc<dyn Widget>: Unpin, *const u8 is !null: Unpin, Rc<dyn ShapeBorder>: Unpin, Rc<dyn Fn(&mut App, usize)>: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin, Rc<Paint>: Unpin, Rc<dyn Fn(&IconThemeData, &mut App, AnyElement) -> IconThemeData>: Unpin,

§

impl UnsafeUnpin for NavigationRail

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>