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:
Scaffold, which can display the navigation rail within aRowof theScaffold::bodyslot.NavigationRailDestination, which is used as a model to create tappable destinations in the navigation rail.BottomNavigationBar, which is a similar navigation widget that’s laid out horizontally.- https://material.io/components/navigation-rail/
- https://m3.material.io/components/navigation-rail
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: boolIndicates 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:
NavigationRailLabelTypefor information on the meaning of different types.
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: boolPin 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: boolPin 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: boolWhether 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§
Sourcepub fn new(
destinations: Vec<NavigationRailDestination>,
selected_index: Option<usize>,
) -> NavigationRail
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.
Sourcepub fn key(self, key: KeyRef) -> NavigationRail
pub fn key(self, key: KeyRef) -> NavigationRail
Dart NavigationRail(key:).
Sourcepub fn background_color(self, background_color: Color) -> NavigationRail
pub fn background_color(self, background_color: Color) -> NavigationRail
Dart NavigationRail(backgroundColor:).
Sourcepub fn extended(self, extended: bool) -> NavigationRail
pub fn extended(self, extended: bool) -> NavigationRail
Dart NavigationRail(extended:).
Sourcepub fn leading<K>(self, leading: impl IntoWidget<K>) -> NavigationRail
pub fn leading<K>(self, leading: impl IntoWidget<K>) -> NavigationRail
Dart NavigationRail(leading:).
Sourcepub fn trailing<K>(self, trailing: impl IntoWidget<K>) -> NavigationRail
pub fn trailing<K>(self, trailing: impl IntoWidget<K>) -> NavigationRail
Dart NavigationRail(trailing:).
Sourcepub fn on_destination_selected(
self,
on_destination_selected: impl Fn(&mut App, usize) + 'static,
) -> NavigationRail
pub fn on_destination_selected( self, on_destination_selected: impl Fn(&mut App, usize) + 'static, ) -> NavigationRail
Dart NavigationRail(onDestinationSelected:).
Sourcepub fn elevation(self, elevation: f64) -> NavigationRail
pub fn elevation(self, elevation: f64) -> NavigationRail
Dart NavigationRail(elevation:).
Sourcepub fn group_alignment(self, group_alignment: f64) -> NavigationRail
pub fn group_alignment(self, group_alignment: f64) -> NavigationRail
Dart NavigationRail(groupAlignment:).
Sourcepub fn label_type(self, label_type: NavigationRailLabelType) -> NavigationRail
pub fn label_type(self, label_type: NavigationRailLabelType) -> NavigationRail
Dart NavigationRail(labelType:).
Sourcepub fn unselected_label_text_style(
self,
unselected_label_text_style: TextStyle,
) -> NavigationRail
pub fn unselected_label_text_style( self, unselected_label_text_style: TextStyle, ) -> NavigationRail
Dart NavigationRail(unselectedLabelTextStyle:).
Sourcepub fn selected_label_text_style(
self,
selected_label_text_style: TextStyle,
) -> NavigationRail
pub fn selected_label_text_style( self, selected_label_text_style: TextStyle, ) -> NavigationRail
Dart NavigationRail(selectedLabelTextStyle:).
Sourcepub fn unselected_icon_theme(
self,
unselected_icon_theme: IconThemeData,
) -> NavigationRail
pub fn unselected_icon_theme( self, unselected_icon_theme: IconThemeData, ) -> NavigationRail
Dart NavigationRail(unselectedIconTheme:).
Sourcepub fn selected_icon_theme(
self,
selected_icon_theme: IconThemeData,
) -> NavigationRail
pub fn selected_icon_theme( self, selected_icon_theme: IconThemeData, ) -> NavigationRail
Dart NavigationRail(selectedIconTheme:).
Sourcepub fn min_width(self, min_width: f64) -> NavigationRail
pub fn min_width(self, min_width: f64) -> NavigationRail
Dart NavigationRail(minWidth:).
Sourcepub fn min_extended_width(self, min_extended_width: f64) -> NavigationRail
pub fn min_extended_width(self, min_extended_width: f64) -> NavigationRail
Dart NavigationRail(minExtendedWidth:).
Sourcepub fn use_indicator(self, use_indicator: bool) -> NavigationRail
pub fn use_indicator(self, use_indicator: bool) -> NavigationRail
Dart NavigationRail(useIndicator:).
Sourcepub fn indicator_color(self, indicator_color: Color) -> NavigationRail
pub fn indicator_color(self, indicator_color: Color) -> NavigationRail
Dart NavigationRail(indicatorColor:).
Sourcepub fn indicator_shape(
self,
indicator_shape: impl Into<ShapeBorderRef>,
) -> NavigationRail
pub fn indicator_shape( self, indicator_shape: impl Into<ShapeBorderRef>, ) -> NavigationRail
Dart NavigationRail(indicatorShape:).
Sourcepub fn leading_at_top(self, leading_at_top: bool) -> NavigationRail
pub fn leading_at_top(self, leading_at_top: bool) -> NavigationRail
Dart NavigationRail(leadingAtTop:).
Sourcepub fn trailing_at_bottom(self, trailing_at_bottom: bool) -> NavigationRail
pub fn trailing_at_bottom(self, trailing_at_bottom: bool) -> NavigationRail
Dart NavigationRail(trailingAtBottom:).
Sourcepub fn scrollable(self, scrollable: bool) -> NavigationRail
pub fn scrollable(self, scrollable: bool) -> NavigationRail
Dart NavigationRail(scrollable:).
Sourcepub fn main_axis_alignment(
self,
main_axis_alignment: MainAxisAlignment,
) -> NavigationRail
pub fn main_axis_alignment( self, main_axis_alignment: MainAxisAlignment, ) -> NavigationRail
Dart NavigationRail(mainAxisAlignment:).
Sourcepub fn extended_animation(
app: &mut App,
context: BuildContext,
) -> AnyAnimation<f64>
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§type State = NavigationRailState
type State = NavigationRailState
Source§fn create_state(&self) -> NavigationRailState
fn create_state(&self) -> NavigationRailState
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Widget::type_name. A stateful form another widget kind becomes (an animated or
status transition widget) names the widget it wraps.Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.