Skip to main content

NavigationDrawer

Struct NavigationDrawer 

Source
pub struct NavigationDrawer {
Show 13 fields pub key: Option<KeyRef>, pub background_color: Option<Color>, pub shadow_color: Option<Color>, pub surface_tint_color: Option<Color>, pub elevation: Option<f64>, pub indicator_color: Option<Color>, pub indicator_shape: Option<ShapeBorderRef>, pub children: Vec<WidgetRef>, pub header: Option<WidgetRef>, pub footer: Option<WidgetRef>, pub selected_index: Option<i32>, pub on_destination_selected: Option<ValueChanged<i32>>, pub tile_padding: EdgeInsetsGeometry,
}
Expand description

Material Design Navigation Drawer component.

On top of Drawers, Navigation drawers offer a persistent and convenient way to switch between primary destinations in an app.

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

The children are a list of widgets to be displayed in the drawer. These can be a mixture of any widgets, but there is special handling for NavigationDrawerDestinations. They are treated as a group and when one is selected, the on_destination_selected is called with the index into the group that corresponds to the selected destination.

See also:

  • Scaffold::drawer, where one specifies a Drawer so that it can be shown.
  • Scaffold::of, to obtain the current ScaffoldState, which manages the display and animation of the drawer.
  • ScaffoldState::open_drawer, which displays its Drawer, if any.
  • https://material.io/design/components/navigation-drawer.html

Fields§

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

The background color of the Material that holds the NavigationDrawer’s contents.

If this is null, then NavigationDrawerThemeData::background_color is used. If that is also null, then it falls back to ColorScheme::surface_container_low.

§shadow_color: Option<Color>

The color used for the drop shadow to indicate elevation.

If null, NavigationDrawerThemeData::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 surface tint of the Material that holds the NavigationDrawer’s contents.

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 this is null, then NavigationDrawerThemeData::surface_tint_color is used. If that is also null, the default value is Colors::TRANSPARENT.

§elevation: Option<f64>

The elevation of the NavigationDrawer itself.

If null, NavigationDrawerThemeData::elevation is used. If that is also null, it will be 1.0.

§indicator_color: Option<Color>

The color of the indicator_shape when this destination is selected.

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

§indicator_shape: Option<ShapeBorderRef>

The shape of the selected indicator.

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

§children: Vec<WidgetRef>

Defines the appearance of the items within the navigation drawer.

The list contains NavigationDrawerDestination widgets and/or customized widgets like headlines and dividers.

§header: Option<WidgetRef>

A widget to display at the top of the layout.

Typically used for titles, navigation bars, or other header content.

§footer: Option<WidgetRef>

A widget to display at the bottom of the layout.

Typically used for actions, navigation controls, or other footer content.

§selected_index: Option<i32>

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

A valid selected_index satisfies 0 <= selected_index < number of NavigationDrawerDestination. For an invalid selected_index like -1, all destinations will appear unselected.

§on_destination_selected: Option<ValueChanged<i32>>

Called when one of the NavigationDrawerDestination children is selected.

This callback usually updates the int passed to selected_index.

Upon updating selected_index, the NavigationDrawer will be rebuilt.

§tile_padding: EdgeInsetsGeometry

Defines the padding for NavigationDrawerDestination widgets (Drawer items).

Defaults to EdgeInsets.symmetric(horizontal: 12.0).

Implementations§

Source§

impl NavigationDrawer

Source

pub fn new(children: impl IntoIterator<Item = WidgetRef>) -> NavigationDrawer

Creates a Material Design Navigation Drawer component.

Source

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

Dart NavigationDrawer(key:).

Source

pub fn header<K>(self, header: impl IntoWidget<K>) -> NavigationDrawer

Dart NavigationDrawer(header:).

Source

pub fn footer<K>(self, footer: impl IntoWidget<K>) -> NavigationDrawer

Dart NavigationDrawer(footer:).

Source

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

Dart NavigationDrawer(backgroundColor:).

Source

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

Dart NavigationDrawer(shadowColor:).

Source

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

Dart NavigationDrawer(surfaceTintColor:).

Source

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

Dart NavigationDrawer(elevation:).

Source

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

Dart NavigationDrawer(indicatorColor:).

Source

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

Dart NavigationDrawer(indicatorShape:).

Source

pub fn on_destination_selected( self, on_destination_selected: ValueChanged<i32>, ) -> NavigationDrawer

Dart NavigationDrawer(onDestinationSelected:).

Source

pub fn selected_index(self, selected_index: Option<i32>) -> NavigationDrawer

Dart NavigationDrawer(selectedIndex:); None selects no destination.

Source

pub fn tile_padding( self, tile_padding: impl Into<EdgeInsetsGeometry>, ) -> NavigationDrawer

Dart NavigationDrawer(tilePadding:).

Trait Implementations§

Source§

impl Debug for NavigationDrawer

Source§

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

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

impl StatelessWidget for NavigationDrawer

Source§

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

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 debug_check_constructor(&self)

Dart’s constructor asserts that relate two or more arguments. Read more
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 NavigationDrawer

§

impl !Send for NavigationDrawer

§

impl !Sync for NavigationDrawer

§

impl !UnwindSafe for NavigationDrawer

§

impl Forget for NavigationDrawer

§

impl Freeze for NavigationDrawer
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn ShapeBorder> is !null: Freeze, PhantomData<RcInner<dyn ShapeBorder>>: Freeze, *const u8 is !null: Freeze, PhantomData<Rc<dyn Widget>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const RcInner<dyn Fn(&mut App, i32)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, i32)>>: Freeze,

§

impl Move for NavigationDrawer

§

impl Unpin for NavigationDrawer
where Rc<dyn Key>: Unpin, Rc<dyn ShapeBorder>: Unpin, *const u8 is !null: Unpin, Rc<dyn Widget>: Unpin, Rc<dyn Fn(&mut App, i32)>: Unpin,

§

impl UnsafeUnpin for NavigationDrawer
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ShapeBorder>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Rc<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, i32)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, i32)>>: 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>