Skip to main content

BottomNavigationBar

Struct BottomNavigationBar 

Source
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 four items. The selected item is rendered with the selected_item_color if it’s non-null, otherwise the theme’s ColorScheme::primary color is used for Brightness::Light themes and ColorScheme::secondary for Brightness::Dark themes. If background_color is null, The navigation bar’s background color defaults to the Material background color, ThemeData::canvas_color (essentially opaque white).
  • BottomNavigationBarType::Shifting, the default when there are four or more items. If selected_item_color is null, all items are rendered in white. The navigation bar’s background color is the same as the BottomNavigationBarItem::background_color of 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.

  1. Instead of using BottomNavigationBar::items, which takes a list of BottomNavigationBarItems, use NavigationBar::destinations, which takes a list of widgets. Usually, you use a list of NavigationDestination widgets. Just like BottomNavigationBarItems, NavigationDestinations have a label and icon field.

  2. Instead of using BottomNavigationBar::on_tap, use NavigationBar::on_destination_selected, which is also a callback that is called when the user taps on a navigation bar item.

  3. Instead of using BottomNavigationBar::current_index, use NavigationBar::selected_index, which is also an integer that represents the index of the selected destination.

  4. You may also need to make changes to the styling of the NavigationBar, see the properties in the NavigationBar constructor for more details.

See also:

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: usize

The 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: f64

The 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: f64

The 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: f64

The 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:

  • Feedback for 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:

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: bool

This 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§

Source§

impl BottomNavigationBar

Source

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.

Source

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

Dart BottomNavigationBar(key:).

Source

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

Dart BottomNavigationBar(onTap:).

Source

pub fn current_index(self, current_index: usize) -> BottomNavigationBar

Dart BottomNavigationBar(currentIndex:).

Source

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

Dart BottomNavigationBar(elevation:).

Source

pub fn type(self, type: BottomNavigationBarType) -> BottomNavigationBar

Dart BottomNavigationBar(type:).

Source

pub fn fixed_color(self, fixed_color: Color) -> BottomNavigationBar

Dart BottomNavigationBar(fixedColor:).

Source

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

Dart BottomNavigationBar(backgroundColor:).

Source

pub fn icon_size(self, icon_size: f64) -> BottomNavigationBar

Dart BottomNavigationBar(iconSize:).

Source

pub fn selected_item_color( self, selected_item_color: Color, ) -> BottomNavigationBar

Dart BottomNavigationBar(selectedItemColor:).

Source

pub fn unselected_item_color( self, unselected_item_color: Color, ) -> BottomNavigationBar

Dart BottomNavigationBar(unselectedItemColor:).

Source

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

Dart BottomNavigationBar(selectedIconTheme:).

Source

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

Dart BottomNavigationBar(unselectedIconTheme:).

Source

pub fn selected_font_size(self, selected_font_size: f64) -> BottomNavigationBar

Dart BottomNavigationBar(selectedFontSize:).

Source

pub fn unselected_font_size( self, unselected_font_size: f64, ) -> BottomNavigationBar

Dart BottomNavigationBar(unselectedFontSize:).

Source

pub fn selected_label_style( self, selected_label_style: TextStyle, ) -> BottomNavigationBar

Dart BottomNavigationBar(selectedLabelStyle:).

Source

pub fn unselected_label_style( self, unselected_label_style: TextStyle, ) -> BottomNavigationBar

Dart BottomNavigationBar(unselectedLabelStyle:).

Source

pub fn show_selected_labels( self, show_selected_labels: bool, ) -> BottomNavigationBar

Dart BottomNavigationBar(showSelectedLabels:).

Source

pub fn show_unselected_labels( self, show_unselected_labels: bool, ) -> BottomNavigationBar

Dart BottomNavigationBar(showUnselectedLabels:).

Source

pub fn mouse_cursor( self, mouse_cursor: impl Into<MouseCursorRef>, ) -> BottomNavigationBar

Dart BottomNavigationBar(mouseCursor:).

Source

pub fn enable_feedback(self, enable_feedback: bool) -> BottomNavigationBar

Dart BottomNavigationBar(enableFeedback:).

Source

pub fn landscape_layout( self, landscape_layout: BottomNavigationBarLandscapeLayout, ) -> BottomNavigationBar

Dart BottomNavigationBar(landscapeLayout:).

Source

pub fn use_legacy_color_scheme( self, use_legacy_color_scheme: bool, ) -> BottomNavigationBar

Dart BottomNavigationBar(useLegacyColorScheme:).

Source

pub fn effective_selected_item_color(&self) -> Option<Color>

Dart’s selectedItemColor field, as its constructor fills it: selectedItemColor ?? fixedColor.

Source

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§

impl Debug for BottomNavigationBar

Source§

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

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

impl StatefulWidget for BottomNavigationBar

Source§

type State = BottomNavigationBarState

The state this widget creates.
Source§

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

Source§

fn debug_check_constructor(&self)

Source§

fn create_state(&self) -> BottomNavigationBarState

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 BottomNavigationBar

§

impl !Send for BottomNavigationBar

§

impl !Sync for BottomNavigationBar

§

impl !UnwindSafe for BottomNavigationBar

§

impl Forget for BottomNavigationBar

§

impl Freeze for BottomNavigationBar
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<BottomNavigationBarItem>: 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<Shadow>: Freeze, *const RcInner<dyn Fn(&IconThemeData, &mut App, AnyElement) -> IconThemeData> is !null: Freeze, PhantomData<RcInner<dyn Fn(&IconThemeData, &mut App, AnyElement) -> IconThemeData>>: Freeze, PhantomData<u8>: Freeze, PhantomData<String>: Freeze, *const RcInner<Paint> is !null: Freeze, PhantomData<RcInner<Paint>>: Freeze, PhantomData<FontFeature>: Freeze, PhantomData<FontVariation>: Freeze, *const RcInner<dyn MouseCursor> is !null: Freeze, PhantomData<RcInner<dyn MouseCursor>>: Freeze,

§

impl Move for BottomNavigationBar

§

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

§

impl UnsafeUnpin for BottomNavigationBar

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>