Skip to main content

Drawer

Struct Drawer 

Source
pub struct Drawer {
    pub key: Option<KeyRef>,
    pub background_color: Option<Color>,
    pub elevation: Option<f64>,
    pub shadow_color: Option<Color>,
    pub surface_tint_color: Option<Color>,
    pub shape: Option<ShapeBorderRef>,
    pub width: Option<f64>,
    pub child: Option<WidgetRef>,
    pub semantic_label: Option<String>,
    pub clip_behavior: Option<Clip>,
}
Expand description

A Material Design panel that slides in horizontally from the edge of a Scaffold to show navigation links in an application.

There is a Material 3 version of this component, NavigationDrawer, that’s preferred for applications that are configured for Material 3 (see ThemeData::use_material3).

Drawers are typically used with the Scaffold::drawer property. The child of the drawer is usually a ListView whose first child is a DrawerHeader that displays status information about the current user. The remaining drawer children are often constructed with ListTiles, often concluding with an AboutListTile.

The AppBar automatically displays an appropriate IconButton to show the Drawer when a Drawer is available in the Scaffold. The Scaffold automatically handles the edge-swipe gesture to show the drawer.

An open drawer may be closed with a swipe to close gesture, pressing the escape key, by tapping the scrim, or by calling pop route function such as Navigator::pop.

See also:

Fields§

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

Sets the color of the Material that holds all of the Drawer’s contents.

If this is null, then DrawerThemeData::background_color is used. If that is also null, then it falls back to Material’s default.

§elevation: Option<f64>

The z-coordinate at which to place this drawer relative to its parent.

This controls the size of the shadow below the drawer.

If this is null, then DrawerThemeData::elevation is used. If that is also null, then it defaults to 16.0.

§shadow_color: Option<Color>

The color used to paint a drop shadow under the drawer’s Material, which reflects the drawer’s elevation.

If null and ThemeData::use_material3 is true then no drop shadow will be rendered.

If null and ThemeData::use_material3 is false then it will default to ThemeData::shadow_color.

See also:

  • Material::shadow_color, which describes how the drop shadow is painted.
  • elevation, which affects how the drop shadow is painted.
  • surface_tint_color, which can be used to indicate elevation through tinting the background color.
§surface_tint_color: Option<Color>

The color used as a surface tint overlay on the drawer’s background color, which reflects the drawer’s 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.

To disable this feature, set surface_tint_color to Colors::TRANSPARENT.

Defaults to Colors::TRANSPARENT.

See also:

  • Material::surface_tint_color, which describes how the surface tint will be applied to the background color of the drawer.
  • elevation, which affects the opacity of the surface tint.
  • shadow_color, which can be used to indicate elevation through a drop shadow.
§shape: Option<ShapeBorderRef>

The shape of the drawer.

Defines the drawer’s Material::shape.

If this is null, then DrawerThemeData::shape is used. If that is also null, then it falls back to Material’s default.

§width: Option<f64>

The width of the drawer.

If this is null, then DrawerThemeData::width is used. If that is also null, then it falls back to the Material spec’s default (304.0).

§child: Option<WidgetRef>

The widget below this widget in the tree.

Typically a ListView.

§semantic_label: Option<String>

The semantic label of the drawer used by accessibility frameworks to announce screen transitions when the drawer is opened and closed.

If this label is not provided, it will default to MaterialLocalizations::drawer_label.

§clip_behavior: Option<Clip>

The clip_behavior argument specifies how to clip the drawer’s shape.

If the drawer has a shape, it defaults to Clip::HardEdge. Otherwise, defaults to Clip::None.

Implementations§

Source§

impl Drawer

Source

pub fn new() -> Drawer

Creates a Material Design drawer; Dart’s optional named arguments are the setters.

Typically used in the Scaffold::drawer property.

The elevation must be non-negative.

Source

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

Dart Drawer(key:).

Source

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

Dart Drawer(backgroundColor:).

Source

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

Dart Drawer(elevation:).

Source

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

Dart Drawer(shadowColor:).

Source

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

Dart Drawer(surfaceTintColor:).

Source

pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> Drawer

Dart Drawer(shape:).

Source

pub fn width(self, width: f64) -> Drawer

Dart Drawer(width:).

Source

pub fn child<K>(self, child: impl IntoWidget<K>) -> Drawer

Dart Drawer(child:).

Source

pub fn semantic_label(self, semantic_label: impl Into<String>) -> Drawer

Dart Drawer(semanticLabel:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> Drawer

Dart Drawer(clipBehavior:).

Trait Implementations§

Source§

impl Debug for Drawer

Source§

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

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

impl Default for Drawer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl StatelessWidget for Drawer

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 Drawer

§

impl !Send for Drawer

§

impl !Sync for Drawer

§

impl !UnwindSafe for Drawer

§

impl Forget for Drawer

§

impl Freeze for Drawer
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 RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for Drawer

§

impl Unpin for Drawer
where Rc<dyn Key>: Unpin, Rc<dyn ShapeBorder>: Unpin, Rc<dyn Widget>: Unpin, *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Drawer
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 RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: 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>