pub struct BottomNavigationBar {Show 23 fields
pub key: Option<KeyRef>,
pub items: Vec<BottomNavigationBarItem>,
pub on_tap: Option<ValueChanged<usize>>,
pub current_index: usize,
pub elevation: Option<f64>,
pub type: Option<BottomNavigationBarType>,
pub fixed_color: Option<Color>,
pub background_color: Option<Color>,
pub icon_size: f64,
pub selected_item_color: Option<Color>,
pub unselected_item_color: Option<Color>,
pub selected_icon_theme: Option<IconThemeData>,
pub unselected_icon_theme: Option<IconThemeData>,
pub selected_label_style: Option<TextStyle>,
pub unselected_label_style: Option<TextStyle>,
pub selected_font_size: f64,
pub unselected_font_size: f64,
pub show_unselected_labels: Option<bool>,
pub show_selected_labels: Option<bool>,
pub mouse_cursor: Option<MouseCursorRef>,
pub enable_feedback: Option<bool>,
pub landscape_layout: Option<BottomNavigationBarLandscapeLayout>,
pub use_legacy_color_scheme: bool,
}Expand description
A material widget that’s displayed at the bottom of an app for selecting among a small number of views, typically between three and five.
There is an updated version of this component, NavigationBar, that’s
preferred for new applications and applications that are configured
for Material 3 (see ThemeData::use_material3).
The bottom navigation bar consists of multiple items in the form of text labels, icons, or both, laid out on top of a piece of material. It provides quick navigation between the top-level views of an app. For larger screens, side navigation may be a better fit.
A bottom navigation bar is usually used in conjunction with a Scaffold,
where it is provided as the Scaffold::bottom_navigation_bar argument.
The bottom navigation bar’s type changes how its items
are displayed. If not specified, then it’s automatically set to
BottomNavigationBarType::Fixed when there are less than four items, and
BottomNavigationBarType::Shifting otherwise.
The length of items must be at least two and each item’s icon and
label must not be null.
BottomNavigationBarType::Fixed, the default when there are less than fouritems. The selected item is rendered with theselected_item_colorif it’s non-null, otherwise the theme’sColorScheme::primarycolor is used forBrightness::Lightthemes andColorScheme::secondaryforBrightness::Darkthemes. Ifbackground_coloris null, The navigation bar’s background color defaults to theMaterialbackground color,ThemeData::canvas_color(essentially opaque white).BottomNavigationBarType::Shifting, the default when there are four or moreitems. Ifselected_item_coloris null, all items are rendered in white. The navigation bar’s background color is the same as theBottomNavigationBarItem::background_colorof the selected item. In this case it’s assumed that each item will have a different background color and that background color will contrast well with white.
§Updating to NavigationBar
The NavigationBar widget’s visuals
are a little bit different, see the Material 3 spec at
https://m3.material.io/components/navigation-bar/overview for
more details.
The NavigationBar widget’s API is also slightly different.
To update from BottomNavigationBar to NavigationBar, you will
need to make the following changes.
-
Instead of using
BottomNavigationBar::items, which takes a list ofBottomNavigationBarItems, useNavigationBar::destinations, which takes a list of widgets. Usually, you use a list ofNavigationDestinationwidgets. Just likeBottomNavigationBarItems,NavigationDestinations have a label and icon field. -
Instead of using
BottomNavigationBar::on_tap, useNavigationBar::on_destination_selected, which is also a callback that is called when the user taps on a navigation bar item. -
Instead of using
BottomNavigationBar::current_index, useNavigationBar::selected_index, which is also an integer that represents the index of the selected destination. -
You may also need to make changes to the styling of the
NavigationBar, see the properties in theNavigationBarconstructor for more details.
See also:
BottomNavigationBarItemScaffold- https://material.io/design/components/bottom-navigation.html
NavigationBar, this widget’s replacement in Material Design 3.
Fields§
§key: Option<KeyRef>§items: Vec<BottomNavigationBarItem>Defines the appearance of the button items that are arrayed within the bottom navigation bar.
on_tap: Option<ValueChanged<usize>>Called when one of the items is tapped.
The stateful widget that creates the bottom navigation bar needs to keep
track of the index of the selected BottomNavigationBarItem and call
set_state to rebuild the bottom navigation bar with the new
current_index.
current_index: usizeThe index into items for the current active
BottomNavigationBarItem.
elevation: Option<f64>The z-coordinate of this BottomNavigationBar.
If null, defaults to 8.0.
{@macro material_ui.material.elevation}
type: Option<BottomNavigationBarType>Defines the layout and behavior of a BottomNavigationBar.
See documentation for BottomNavigationBarType for information on the
meaning of different types.
fixed_color: Option<Color>What the constructor was given as fixedColor; Dart’s getter is
effective_fixed_color.
background_color: Option<Color>The color of the BottomNavigationBar itself.
If type is BottomNavigationBarType::Shifting and the
items have BottomNavigationBarItem::background_color set, the
items’ background_color will splash and overwrite this color.
icon_size: f64The size of all of the BottomNavigationBarItem icons.
See BottomNavigationBarItem::icon for more information.
selected_item_color: Option<Color>What the constructor was given as selectedItemColor; Dart’s field, which falls
back to fixedColor, is
effective_selected_item_color.
The color of the selected BottomNavigationBarItem::icon and
BottomNavigationBarItem::label.
If null then the ambient BottomNavigationBarThemeData::selected_item_color
is used. If that is also null, ColorScheme::primary is used when
ThemeData::brightness is Brightness::Light, and ColorScheme::secondary
is used when ThemeData::brightness is Brightness::Dark.
unselected_item_color: Option<Color>The color of the unselected BottomNavigationBarItem::icon and
BottomNavigationBarItem::labels.
If null then the ambient BottomNavigationBarThemeData::unselected_item_color
is used. If that is also null, ThemeData::unselected_widget_color is used.
selected_icon_theme: Option<IconThemeData>The size, opacity, and color of the icon in the currently selected
BottomNavigationBarItem::icon.
If this is not provided, the size will default to icon_size,
the color will default to selected_item_color.
It this field is provided, it must contain non-null IconThemeData::size
and IconThemeData::color properties. Also, if this field is supplied,
unselected_icon_theme must be provided.
unselected_icon_theme: Option<IconThemeData>The size, opacity, and color of the icon in the currently unselected
BottomNavigationBarItem::icons.
If this is not provided, the size will default to icon_size,
the color will default to unselected_item_color.
It this field is provided, it must contain non-null IconThemeData::size
and IconThemeData::color properties. Also, if this field is supplied,
selected_icon_theme must be provided.
selected_label_style: Option<TextStyle>The TextStyle of the BottomNavigationBarItem labels when they are
selected.
unselected_label_style: Option<TextStyle>The TextStyle of the BottomNavigationBarItem labels when they are not
selected.
selected_font_size: f64The font size of the BottomNavigationBarItem labels when they are selected.
If TextStyle::font_size of selected_label_style
is non-null, it will be used instead of this.
Defaults to 14.0.
unselected_font_size: f64The font size of the BottomNavigationBarItem labels when they are not
selected.
If TextStyle::font_size of
unselected_label_style is non-null, it will be
used instead of this.
Defaults to 12.0.
show_unselected_labels: Option<bool>Whether the labels are shown for the unselected BottomNavigationBarItems.
show_selected_labels: Option<bool>Whether the labels are shown for the selected BottomNavigationBarItem.
mouse_cursor: Option<MouseCursorRef>The cursor for a mouse pointer when it enters or is hovering over the items.
If mouse_cursor is a WidgetStateMouseCursor, its
resolve method can define the appearance of the cursor depending on whether
WidgetState::Selected is active.
If null, then the value of BottomNavigationBarThemeData::mouse_cursor is used.
If that is also null, then WidgetStateMouseCursor::clickable is used.
enable_feedback: Option<bool>Whether detected gestures should provide acoustic and/or haptic feedback.
For example, on Android a tap will produce a clicking sound and a long-press will produce a short vibration, when feedback is enabled.
See also:
Feedbackfor providing platform-specific feedback to certain actions.
landscape_layout: Option<BottomNavigationBarLandscapeLayout>The arrangement of the bar’s items when the enclosing
MediaQueryData::orientation is Orientation::Landscape.
The following alternatives are supported:
BottomNavigationBarLandscapeLayout::Spread- the items are evenly spaced and spread out across the available width. Each item’s label and icon are arranged in a column.BottomNavigationBarLandscapeLayout::Centered- the items are evenly spaced in a row but only consume as much width as they would in portrait orientation. The row of items is centered within the available width. Each item’s label and icon are arranged in a column.BottomNavigationBarLandscapeLayout::Linear- the items are evenly spaced and each item’s icon and label are lined up in a row instead of a column.
If this property is null, then the value of the enclosing
BottomNavigationBarThemeData::landscape_layout is used. If that
property is also null, then
BottomNavigationBarLandscapeLayout::Spread is used.
This property is null by default.
See also:
ThemeData::bottom_navigation_bar_theme- which can be used to specify bottom navigation bar defaults for an entire application.BottomNavigationBarTheme- which can be used to specify bottom navigation bar defaults for a widget subtree.MediaQuery::orientation_of- which can be used to determine the current orientation.
use_legacy_color_scheme: boolThis flag is controlling how BottomNavigationBar is going to use
the colors provided by the selected_icon_theme,
unselected_icon_theme,
selected_item_color,
unselected_item_color.
The default value is true as the new theming logic is a breaking change.
To opt-in the new theming logic set the flag to false
Implementations§
Sourcepub fn new(items: Vec<BottomNavigationBarItem>) -> BottomNavigationBar
pub fn new(items: Vec<BottomNavigationBarItem>) -> BottomNavigationBar
Creates a bottom navigation bar which is typically used as a
Scaffold’s Scaffold::bottom_navigation_bar argument.
The length of items must be at least two and each item’s icon and
label must not be null.
If type is null then BottomNavigationBarType::Fixed is used when
there are two or three items, BottomNavigationBarType::Shifting
otherwise.
The icon_size, selected_font_size,
unselected_font_size, and
elevation arguments must be non-negative.
If selected_label_style.color and
unselected_label_style.color values
are non-null, they will be used instead of
selected_item_color and
unselected_item_color.
If custom IconThemeDatas are used, you must provide both
selected_icon_theme and
unselected_icon_theme, and both
IconThemeData::color and IconThemeData::size must be set.
If use_legacy_color_scheme is set to false
selected_icon_theme values will be used instead of
icon_size and selected_item_color
for selected icons.
unselected_icon_theme values will be used instead of
icon_size and
unselected_item_color for unselected icons.
If both selected_label_style.font_size and
selected_font_size are set,
selected_label_style.font_size will be used.
Only one of selected_item_color and
fixed_color can be specified. The former is preferred,
fixed_color only exists for the sake of backwards
compatibility.
If show_selected_labels is null,
BottomNavigationBarThemeData::show_selected_labels is used. If
BottomNavigationBarThemeData::show_selected_labels is null, then
show_selected_labels defaults to true.
If show_unselected_labels is null,
BottomNavigationBarThemeData::show_unselected_labels is used. If
BottomNavigationBarThemeData::show_selected_labels is null, then
show_unselected_labels defaults to true when
type is BottomNavigationBarType::Fixed and false when
type is BottomNavigationBarType::Shifting.
Sourcepub fn key(self, key: KeyRef) -> BottomNavigationBar
pub fn key(self, key: KeyRef) -> BottomNavigationBar
Dart BottomNavigationBar(key:).
Sourcepub fn on_tap(
self,
on_tap: impl Fn(&mut App, usize) + 'static,
) -> BottomNavigationBar
pub fn on_tap( self, on_tap: impl Fn(&mut App, usize) + 'static, ) -> BottomNavigationBar
Dart BottomNavigationBar(onTap:).
Sourcepub fn current_index(self, current_index: usize) -> BottomNavigationBar
pub fn current_index(self, current_index: usize) -> BottomNavigationBar
Dart BottomNavigationBar(currentIndex:).
Sourcepub fn elevation(self, elevation: f64) -> BottomNavigationBar
pub fn elevation(self, elevation: f64) -> BottomNavigationBar
Dart BottomNavigationBar(elevation:).
Sourcepub fn type(self, type: BottomNavigationBarType) -> BottomNavigationBar
pub fn type(self, type: BottomNavigationBarType) -> BottomNavigationBar
Dart BottomNavigationBar(type:).
Sourcepub fn fixed_color(self, fixed_color: Color) -> BottomNavigationBar
pub fn fixed_color(self, fixed_color: Color) -> BottomNavigationBar
Dart BottomNavigationBar(fixedColor:).
Sourcepub fn background_color(self, background_color: Color) -> BottomNavigationBar
pub fn background_color(self, background_color: Color) -> BottomNavigationBar
Dart BottomNavigationBar(backgroundColor:).
Sourcepub fn icon_size(self, icon_size: f64) -> BottomNavigationBar
pub fn icon_size(self, icon_size: f64) -> BottomNavigationBar
Dart BottomNavigationBar(iconSize:).
Sourcepub fn selected_item_color(
self,
selected_item_color: Color,
) -> BottomNavigationBar
pub fn selected_item_color( self, selected_item_color: Color, ) -> BottomNavigationBar
Dart BottomNavigationBar(selectedItemColor:).
Sourcepub fn unselected_item_color(
self,
unselected_item_color: Color,
) -> BottomNavigationBar
pub fn unselected_item_color( self, unselected_item_color: Color, ) -> BottomNavigationBar
Dart BottomNavigationBar(unselectedItemColor:).
Sourcepub fn selected_icon_theme(
self,
selected_icon_theme: IconThemeData,
) -> BottomNavigationBar
pub fn selected_icon_theme( self, selected_icon_theme: IconThemeData, ) -> BottomNavigationBar
Dart BottomNavigationBar(selectedIconTheme:).
Sourcepub fn unselected_icon_theme(
self,
unselected_icon_theme: IconThemeData,
) -> BottomNavigationBar
pub fn unselected_icon_theme( self, unselected_icon_theme: IconThemeData, ) -> BottomNavigationBar
Dart BottomNavigationBar(unselectedIconTheme:).
Sourcepub fn selected_font_size(self, selected_font_size: f64) -> BottomNavigationBar
pub fn selected_font_size(self, selected_font_size: f64) -> BottomNavigationBar
Dart BottomNavigationBar(selectedFontSize:).
Sourcepub fn unselected_font_size(
self,
unselected_font_size: f64,
) -> BottomNavigationBar
pub fn unselected_font_size( self, unselected_font_size: f64, ) -> BottomNavigationBar
Dart BottomNavigationBar(unselectedFontSize:).
Sourcepub fn selected_label_style(
self,
selected_label_style: TextStyle,
) -> BottomNavigationBar
pub fn selected_label_style( self, selected_label_style: TextStyle, ) -> BottomNavigationBar
Dart BottomNavigationBar(selectedLabelStyle:).
Sourcepub fn unselected_label_style(
self,
unselected_label_style: TextStyle,
) -> BottomNavigationBar
pub fn unselected_label_style( self, unselected_label_style: TextStyle, ) -> BottomNavigationBar
Dart BottomNavigationBar(unselectedLabelStyle:).
Sourcepub fn show_selected_labels(
self,
show_selected_labels: bool,
) -> BottomNavigationBar
pub fn show_selected_labels( self, show_selected_labels: bool, ) -> BottomNavigationBar
Dart BottomNavigationBar(showSelectedLabels:).
Sourcepub fn show_unselected_labels(
self,
show_unselected_labels: bool,
) -> BottomNavigationBar
pub fn show_unselected_labels( self, show_unselected_labels: bool, ) -> BottomNavigationBar
Dart BottomNavigationBar(showUnselectedLabels:).
Sourcepub fn mouse_cursor(
self,
mouse_cursor: impl Into<MouseCursorRef>,
) -> BottomNavigationBar
pub fn mouse_cursor( self, mouse_cursor: impl Into<MouseCursorRef>, ) -> BottomNavigationBar
Dart BottomNavigationBar(mouseCursor:).
Sourcepub fn enable_feedback(self, enable_feedback: bool) -> BottomNavigationBar
pub fn enable_feedback(self, enable_feedback: bool) -> BottomNavigationBar
Dart BottomNavigationBar(enableFeedback:).
Sourcepub fn landscape_layout(
self,
landscape_layout: BottomNavigationBarLandscapeLayout,
) -> BottomNavigationBar
pub fn landscape_layout( self, landscape_layout: BottomNavigationBarLandscapeLayout, ) -> BottomNavigationBar
Dart BottomNavigationBar(landscapeLayout:).
Sourcepub fn use_legacy_color_scheme(
self,
use_legacy_color_scheme: bool,
) -> BottomNavigationBar
pub fn use_legacy_color_scheme( self, use_legacy_color_scheme: bool, ) -> BottomNavigationBar
Dart BottomNavigationBar(useLegacyColorScheme:).
Sourcepub fn effective_selected_item_color(&self) -> Option<Color>
pub fn effective_selected_item_color(&self) -> Option<Color>
Dart’s selectedItemColor field, as its constructor fills it:
selectedItemColor ?? fixedColor.
Sourcepub fn effective_fixed_color(&self) -> Option<Color>
pub fn effective_fixed_color(&self) -> Option<Color>
The value of selected_item_color.
This getter only exists for backwards compatibility, the
selected_item_color property is preferred.
Trait Implementations§
Source§type State = BottomNavigationBarState
type State = BottomNavigationBarState
Source§fn create_state(&self) -> BottomNavigationBarState
fn create_state(&self) -> BottomNavigationBarState
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.