Skip to main content

MaterialBanner

Struct MaterialBanner 

Source
pub struct MaterialBanner {
Show 18 fields pub key: Option<KeyRef>, pub content: WidgetRef, pub content_text_style: Option<TextStyle>, pub actions: Vec<WidgetRef>, pub elevation: Option<f64>, pub leading: Option<WidgetRef>, pub min_action_bar_height: f64, pub background_color: Option<Color>, pub surface_tint_color: Option<Color>, pub shadow_color: Option<Color>, pub divider_color: Option<Color>, pub padding: Option<EdgeInsetsGeometry>, pub margin: Option<EdgeInsetsGeometry>, pub leading_padding: Option<EdgeInsetsGeometry>, pub force_actions_below: bool, pub overflow_alignment: OverflowBarAlignment, pub animation: Option<AnimationRef<f64>>, pub on_visible: Option<VoidCallback>,
}
Expand description

A Material Design banner.

A banner displays an important, succinct message, and provides actions for users to address (or dismiss the banner). A user action is required for it to be dismissed.

Banners should be displayed at the top of the screen, below a top app bar. They are persistent and non-modal, allowing the user to either ignore them or interact with them at any time.

Banners placed directly into the widget tree are static.

MaterialBanner’s can also be presented through a ScaffoldMessenger, with ScaffoldMessengerState::show_material_banner.

The actions will be placed beside the content if there is only one. Otherwise, the actions will be placed below the content. Use force_actions_below to override this behavior.

If the actions placed below the content, they will be laid out in a row. If there isn’t sufficient room to display everything, they are laid out in a column instead.

The actions and content must be provided. An optional leading widget (typically an Image) can also be provided. The content_text_style and background_color can be provided to customize the banner.

This widget is unrelated to the widgets library Banner widget.

Fields§

§key: Option<KeyRef>§content: WidgetRef

The content of the MaterialBanner.

Typically a Text widget.

§content_text_style: Option<TextStyle>

Style for the text in the content of the MaterialBanner.

If None, MaterialBannerThemeData::content_text_style is used. If that is also None, TextTheme::body_medium of ThemeData::text_theme is used.

§actions: Vec<WidgetRef>

The set of actions that are displayed at the bottom or trailing side of the MaterialBanner.

Typically this is a list of TextButton widgets.

When a MaterialBanner is shown by a ScaffoldMessenger above the Navigator, such as the one created by MaterialApp, it stays visible after the route that showed it is popped, and that route’s BuildContext is deactivated. If an action callback dismisses the banner using ScaffoldMessenger::of, avoid passing a BuildContext from the route that showed the banner. Instead, either wrap the action widget in a Builder so its callback uses the banner’s own BuildContext, or capture the ScaffoldMessengerState before calling ScaffoldMessengerState::show_material_banner.

§elevation: Option<f64>

The z-coordinate at which to place the material banner.

This controls the size of the shadow below the material banner.

Defines the banner’s Material::elevation.

If this property is None, then the ambient MaterialBannerThemeData::elevation is used, if that is also None, the default value is 0. If the elevation is 0, the Scaffold’s body will be pushed down by the MaterialBanner when used with ScaffoldMessenger.

§leading: Option<WidgetRef>

The (optional) leading widget of the MaterialBanner.

Typically an Icon widget.

§min_action_bar_height: f64

The optional minimum action bar height.

Default to 52.0.

§background_color: Option<Color>

The color of the surface of this MaterialBanner.

If None, MaterialBannerThemeData::background_color is used. If that is also None, ColorScheme::surface_container_low of ThemeData::color_scheme is used.

§surface_tint_color: Option<Color>

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

If None, MaterialBannerThemeData::surface_tint_color is used. If that is also None, the default value is Colors::TRANSPARENT.

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.

§shadow_color: Option<Color>

The color of the shadow below the MaterialBanner.

If this property is None, then the ambient MaterialBannerThemeData::shadow_color is used. If that is also None, the default value is None.

§divider_color: Option<Color>

The color of the divider.

If this property is None, then the ambient MaterialBannerThemeData::divider_color is used. If that is also None, the default value is ColorScheme::surface_variant.

§padding: Option<EdgeInsetsGeometry>

The amount of space by which to inset the content.

If the actions are below the content, this defaults to EdgeInsetsDirectional.only(start: 16.0, top: 24.0, end: 16.0, bottom: 4.0).

If the actions are trailing the content, this defaults to EdgeInsetsDirectional.only(start: 16.0, top: 2.0).

§margin: Option<EdgeInsetsGeometry>

Empty space to surround the MaterialBanner.

If the margin is None then this defaults to 0 if the banner’s elevation is 0, 10 otherwise.

§leading_padding: Option<EdgeInsetsGeometry>

The amount of space by which to inset the leading widget.

This defaults to EdgeInsetsDirectional.only(end: 16.0).

§force_actions_below: bool

An override to force the actions to be below the content regardless of how many there are.

If this is true, the actions will be placed below the content. If this is false, the actions will be placed on the trailing side of the content if actions’s length is 1 and below the content if greater than 1.

Defaults to false.

§overflow_alignment: OverflowBarAlignment

The horizontal alignment of the actions when the actions laid out in a column.

Defaults to OverflowBarAlignment::End.

§animation: Option<AnimationRef<f64>>

The animation driving the entrance and exit of the material banner when presented by the ScaffoldMessenger.

§on_visible: Option<VoidCallback>

Called the first time that the material banner is visible within a Scaffold when presented by the ScaffoldMessenger.

Implementations§

Source§

impl MaterialBanner

Source

pub fn new<K>( content: impl IntoWidget<K>, actions: Vec<WidgetRef>, ) -> MaterialBanner

Creates a MaterialBanner; Dart’s optional arguments are the setters.

The length of the actions list must not be empty. The elevation must be None or non-negative.

Source

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

Dart MaterialBanner(key:).

Source

pub fn content_text_style(self, content_text_style: TextStyle) -> MaterialBanner

Dart MaterialBanner(contentTextStyle:).

Source

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

Dart MaterialBanner(elevation:).

Source

pub fn leading<K>(self, leading: impl IntoWidget<K>) -> MaterialBanner

Dart MaterialBanner(leading:).

Source

pub fn min_action_bar_height(self, min_action_bar_height: f64) -> MaterialBanner

Dart MaterialBanner(minActionBarHeight:).

Source

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

Dart MaterialBanner(backgroundColor:).

Source

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

Dart MaterialBanner(surfaceTintColor:).

Source

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

Dart MaterialBanner(shadowColor:).

Source

pub fn divider_color(self, divider_color: Color) -> MaterialBanner

Dart MaterialBanner(dividerColor:).

Source

pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> MaterialBanner

Dart MaterialBanner(padding:).

Source

pub fn margin(self, margin: impl Into<EdgeInsetsGeometry>) -> MaterialBanner

Dart MaterialBanner(margin:).

Source

pub fn leading_padding( self, leading_padding: impl Into<EdgeInsetsGeometry>, ) -> MaterialBanner

Dart MaterialBanner(leadingPadding:).

Source

pub fn force_actions_below(self, force_actions_below: bool) -> MaterialBanner

Dart MaterialBanner(forceActionsBelow:).

Source

pub fn overflow_alignment( self, overflow_alignment: OverflowBarAlignment, ) -> MaterialBanner

Dart MaterialBanner(overflowAlignment:).

Source

pub fn animation(self, animation: AnimationRef<f64>) -> MaterialBanner

Dart MaterialBanner(animation:).

Source

pub fn on_visible( self, on_visible: impl Fn(&mut App) + 'static, ) -> MaterialBanner

Dart MaterialBanner(onVisible:).

Source

pub fn create_animation_controller( app: &mut App, vsync: impl TickerProvider, ) -> Ref<AnimationController>

Creates an animation controller useful for driving a MaterialBanner’s entrance and exit animation.

Source

pub fn with_animation( &self, new_animation: AnimationRef<f64>, fallback_key: Option<KeyRef>, ) -> MaterialBanner

Creates a copy of this material banner but with the animation replaced with the given animation.

If the original material banner lacks a key, the newly created material banner will use the given fallback key.

Trait Implementations§

Source§

impl Clone for MaterialBanner

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MaterialBanner

Source§

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

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

impl StatefulWidget for MaterialBanner

Source§

type State = MaterialBannerState

The state this widget creates.
Source§

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

Source§

fn create_state(&self) -> MaterialBannerState

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

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 MaterialBanner

§

impl !Send for MaterialBanner

§

impl !Sync for MaterialBanner

§

impl !UnwindSafe for MaterialBanner

§

impl Forget for MaterialBanner

§

impl Freeze for MaterialBanner
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, &'static dyn ColorExtension: Freeze, *const RcInner<dyn ColorExtension> is !null: Freeze, PhantomData<RcInner<dyn ColorExtension>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<String>: Freeze, *const RcInner<Paint> is !null: Freeze, PhantomData<RcInner<Paint>>: Freeze, PhantomData<Shadow>: Freeze, PhantomData<FontFeature>: Freeze, PhantomData<FontVariation>: Freeze, PhantomData<Rc<dyn Widget>>: Freeze, NonZero<u32>: Freeze, &'static AnimationVTable<f64>: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze,

§

impl Move for MaterialBanner

§

impl Unpin for MaterialBanner
where Rc<dyn Key>: Unpin, Rc<dyn Widget>: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin, *const u8 is !null: Unpin, Rc<Paint>: Unpin, NonZero<u32>: Unpin, &'static AnimationVTable<f64>: Unpin, Rc<Keep>: Unpin, Rc<dyn Fn(&mut App)>: Unpin,

§

impl UnsafeUnpin for MaterialBanner
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin, &'static dyn ColorExtension: UnsafeUnpin, *const RcInner<dyn ColorExtension> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ColorExtension>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, *const RcInner<Paint> is !null: UnsafeUnpin, PhantomData<RcInner<Paint>>: UnsafeUnpin, PhantomData<Shadow>: UnsafeUnpin, PhantomData<FontFeature>: UnsafeUnpin, PhantomData<FontVariation>: UnsafeUnpin, PhantomData<Rc<dyn Widget>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static AnimationVTable<f64>: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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>