Skip to main content

NavigationBar

Struct NavigationBar 

Source
pub struct NavigationBar {
Show 17 fields pub key: Option<KeyRef>, pub animation_duration: Option<Duration>, pub selected_index: usize, pub destinations: Vec<WidgetRef>, pub on_destination_selected: Option<ValueChanged<usize>>, pub background_color: Option<Color>, pub elevation: Option<f64>, pub shadow_color: Option<Color>, pub surface_tint_color: Option<Color>, pub indicator_color: Option<Color>, pub indicator_shape: Option<ShapeBorderRef>, pub height: Option<f64>, pub label_behavior: Option<NavigationDestinationLabelBehavior>, pub overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>, pub label_text_style: Option<WidgetStatePropertyRef<Option<TextStyle>>>, pub label_padding: Option<EdgeInsetsGeometry>, pub maintain_bottom_view_padding: bool,
}
Expand description

Material 3 Navigation Bar component.

Learn more about NavigationBar on the Flutter YouTube channel.

Navigation bars offer a persistent and convenient way to switch between primary destinations in an app.

This widget does not adjust its size with the ThemeData::visual_density.

The MediaQueryData::text_scaler does not adjust the size of this widget but rather the size of the Tooltips displayed on long presses of the destinations.

The style for the icons and text are not affected by parent DefaultTextStyles or IconThemes but rather controlled by parameters or the NavigationBarThemeData.

This widget holds a collection of destinations (usually NavigationDestinations).

See also:

Fields§

§key: Option<KeyRef>§animation_duration: Option<Duration>

Determines the transition time for each destination as it goes between selected and unselected.

§selected_index: usize

Determines which one of the destinations is currently selected.

When this is updated, the destination (from destinations) at selected_index goes from unselected to selected.

§destinations: Vec<WidgetRef>

The list of destinations (usually NavigationDestinations) in this NavigationBar.

When selected_index is updated, the destination from this list at selected_index will animate from 0 (unselected) to 1.0 (selected). When the animation is increasing or completed, the destination is considered selected, when the animation is decreasing or dismissed, the destination is considered unselected.

§on_destination_selected: Option<ValueChanged<usize>>

Called when one of the destinations is selected.

This callback usually updates the int passed to selected_index.

Upon updating selected_index, the NavigationBar will be rebuilt.

§background_color: Option<Color>

The color of the NavigationBar itself.

If null, NavigationBarThemeData::background_color is used. If that is also null, then if ThemeData::use_material3 is true, the value is ColorScheme::surface_container. If that is false, the default blends ColorScheme::surface and ColorScheme::on_surface using an ElevationOverlay.

§elevation: Option<f64>

The elevation of the NavigationBar itself.

If null, NavigationBarThemeData::elevation is used. If that is also null, then if ThemeData::use_material3 is true then it will be 3.0 otherwise 0.0.

§shadow_color: Option<Color>

The color used for the drop shadow to indicate elevation.

If null, NavigationBarThemeData::shadow_color is used. If that is also null, the default value is Colors::TRANSPARENT which indicates that no drop shadow will be displayed.

See Material::shadow_color for more details on drop shadows.

§surface_tint_color: Option<Color>

The color used as an overlay on background_color to indicate elevation.

This is not recommended for use. Material 3 spec introduced a set of tone-based surfaces and surface containers in its ColorScheme, which provide more flexibility. The intention is to eventually remove surface tint color from the framework.

If null, NavigationBarThemeData::surface_tint_color is used. If that is also null, the default value is Colors::TRANSPARENT.

See Material::surface_tint_color for more details on how this overlay is applied.

§indicator_color: Option<Color>

The color of the indicator_shape when this destination is selected.

If null, NavigationBarThemeData::indicator_color is used. If that is also null and ThemeData::use_material3 is true, ColorScheme::secondary_container is used. Otherwise, ColorScheme::secondary with an opacity of 0.24 is used.

§indicator_shape: Option<ShapeBorderRef>

The shape of the selected indicator.

If null, NavigationBarThemeData::indicator_shape is used. If that is also null and ThemeData::use_material3 is true, StadiumBorder is used. Otherwise, RoundedRectangleBorder with a circular border radius of 16 is used.

§height: Option<f64>

The height of the NavigationBar itself.

If this is used in Scaffold::bottom_navigation_bar and the scaffold is full-screen, the safe area padding is also added to the height automatically.

The height does not adjust with ThemeData::visual_density or MediaQueryData::text_scaler as this component loses usability at larger and smaller sizes due to the truncating of labels or smaller tap targets.

If null, NavigationBarThemeData::height is used. If that is also null, the default is 80.

§label_behavior: Option<NavigationDestinationLabelBehavior>

Defines how the destinations’ labels will be laid out and when they’ll be displayed.

Can be used to show all labels, show only the selected label, or hide all labels.

If null, NavigationBarThemeData::label_behavior is used. If that is also null, the default is NavigationDestinationLabelBehavior::AlwaysShow.

§overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>

The highlight color that’s typically used to indicate that the NavigationDestination is focused, hovered, or pressed.

§label_text_style: Option<WidgetStatePropertyRef<Option<TextStyle>>>

The text style of the label.

If null, NavigationBarThemeData::label_text_style is used. If that is also null, the default text style is TextTheme::label_medium with ColorScheme::on_surface when the destination is selected, and ColorScheme::on_surface_variant when the destination is unselected, and ColorScheme::on_surface_variant with an opacity of 0.38 when the destination is disabled.

If ThemeData::use_material3 is false, then the default text style is TextTheme::label_small with ColorScheme::on_surface.

§label_padding: Option<EdgeInsetsGeometry>

The padding around the NavigationDestination::label widget.

When label_padding is null, NavigationBarThemeData::label_padding is used. If that is also null, the default padding is 4 pixels on the top.

§maintain_bottom_view_padding: bool

Specifies whether the underlying SafeArea should maintain the bottom MediaQueryData::view_padding instead of the bottom MediaQueryData::padding.

When true, this will prevent the NavigationBar from shifting when opening a software keyboard due to the change in the padding value, especially when the app uses SystemUiMode::EdgeToEdge, which renders the system bars over the application instead of outside it.

Defaults to false.

See also:

  • SafeArea::maintain_bottom_view_padding, which specifies whether the SafeArea should maintain the bottom MediaQueryData::view_padding.
  • SystemUiMode::EdgeToEdge, which sets a fullscreen display with status and navigation elements rendered over the application.

Implementations§

Source§

impl NavigationBar

Source

pub fn new(destinations: impl IntoIterator<Item = WidgetRef>) -> NavigationBar

Creates a Material 3 Navigation Bar component.

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

Source

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

Dart NavigationBar(key:).

Source

pub fn animation_duration(self, animation_duration: Duration) -> NavigationBar

Dart NavigationBar(animationDuration:).

Source

pub fn selected_index(self, selected_index: usize) -> NavigationBar

Dart NavigationBar(selectedIndex:).

Source

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

Dart NavigationBar(onDestinationSelected:).

Source

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

Dart NavigationBar(backgroundColor:).

Source

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

Dart NavigationBar(elevation:).

Source

pub fn shadow_color(self, shadow_color: Color) -> NavigationBar

Dart NavigationBar(shadowColor:).

Source

pub fn surface_tint_color(self, surface_tint_color: Color) -> NavigationBar

Dart NavigationBar(surfaceTintColor:).

Source

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

Dart NavigationBar(indicatorColor:).

Source

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

Dart NavigationBar(indicatorShape:).

Source

pub fn height(self, height: f64) -> NavigationBar

Dart NavigationBar(height:).

Source

pub fn label_behavior( self, label_behavior: NavigationDestinationLabelBehavior, ) -> NavigationBar

Dart NavigationBar(labelBehavior:).

Source

pub fn overlay_color( self, overlay_color: WidgetStatePropertyRef<Option<Color>>, ) -> NavigationBar

Dart NavigationBar(overlayColor:).

Source

pub fn label_text_style( self, label_text_style: WidgetStatePropertyRef<Option<TextStyle>>, ) -> NavigationBar

Dart NavigationBar(labelTextStyle:).

Source

pub fn label_padding( self, label_padding: impl Into<EdgeInsetsGeometry>, ) -> NavigationBar

Dart NavigationBar(labelPadding:).

Source

pub fn maintain_bottom_view_padding( self, maintain_bottom_view_padding: bool, ) -> NavigationBar

Dart NavigationBar(maintainBottomViewPadding:).

Trait Implementations§

Source§

impl Debug for NavigationBar

Source§

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

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

impl StatelessWidget for NavigationBar

Source§

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

Source§

fn debug_check_constructor(&self)

Dart’s constructor asserts that relate two or more arguments. Read more
Source§

fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef

Describes the part of the user interface represented by this widget. 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)>

Dart’s this is PreferredSizeWidget: a widget that implements PreferredSizeWidget answers with itself, which is what a parent asking an erased child for its preferred size reads.

Auto Trait Implementations§

§

impl !RefUnwindSafe for NavigationBar

§

impl !Send for NavigationBar

§

impl !Sync for NavigationBar

§

impl !UnwindSafe for NavigationBar

§

impl Forget for NavigationBar

§

impl Freeze for NavigationBar
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<Rc<dyn Widget>>: Freeze, *const RcInner<dyn Fn(&mut App, usize)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, usize)>>: Freeze, *const RcInner<dyn ShapeBorder> is !null: Freeze, PhantomData<RcInner<dyn ShapeBorder>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<TextStyle>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<TextStyle>>>>: Freeze,

§

impl Move for NavigationBar

§

impl Unpin for NavigationBar

§

impl UnsafeUnpin for NavigationBar
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Rc<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, usize)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, usize)>>: UnsafeUnpin, *const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ShapeBorder>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<TextStyle>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<TextStyle>>>>: UnsafeUnpin,

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<StatelessKind> for W
where W: StatelessWidget,

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>