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: WidgetRefThe 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: f64The 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: boolAn 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: OverflowBarAlignmentThe 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
impl MaterialBanner
Sourcepub fn new<K>(
content: impl IntoWidget<K>,
actions: Vec<WidgetRef>,
) -> MaterialBanner
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.
Sourcepub fn key(self, key: KeyRef) -> MaterialBanner
pub fn key(self, key: KeyRef) -> MaterialBanner
Dart MaterialBanner(key:).
Sourcepub fn content_text_style(self, content_text_style: TextStyle) -> MaterialBanner
pub fn content_text_style(self, content_text_style: TextStyle) -> MaterialBanner
Dart MaterialBanner(contentTextStyle:).
Sourcepub fn elevation(self, elevation: f64) -> MaterialBanner
pub fn elevation(self, elevation: f64) -> MaterialBanner
Dart MaterialBanner(elevation:).
Sourcepub fn leading<K>(self, leading: impl IntoWidget<K>) -> MaterialBanner
pub fn leading<K>(self, leading: impl IntoWidget<K>) -> MaterialBanner
Dart MaterialBanner(leading:).
Sourcepub fn min_action_bar_height(self, min_action_bar_height: f64) -> MaterialBanner
pub fn min_action_bar_height(self, min_action_bar_height: f64) -> MaterialBanner
Dart MaterialBanner(minActionBarHeight:).
Sourcepub fn background_color(self, background_color: Color) -> MaterialBanner
pub fn background_color(self, background_color: Color) -> MaterialBanner
Dart MaterialBanner(backgroundColor:).
Sourcepub fn surface_tint_color(self, surface_tint_color: Color) -> MaterialBanner
pub fn surface_tint_color(self, surface_tint_color: Color) -> MaterialBanner
Dart MaterialBanner(surfaceTintColor:).
Sourcepub fn shadow_color(self, shadow_color: Color) -> MaterialBanner
pub fn shadow_color(self, shadow_color: Color) -> MaterialBanner
Dart MaterialBanner(shadowColor:).
Sourcepub fn divider_color(self, divider_color: Color) -> MaterialBanner
pub fn divider_color(self, divider_color: Color) -> MaterialBanner
Dart MaterialBanner(dividerColor:).
Sourcepub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> MaterialBanner
pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> MaterialBanner
Dart MaterialBanner(padding:).
Sourcepub fn margin(self, margin: impl Into<EdgeInsetsGeometry>) -> MaterialBanner
pub fn margin(self, margin: impl Into<EdgeInsetsGeometry>) -> MaterialBanner
Dart MaterialBanner(margin:).
Sourcepub fn leading_padding(
self,
leading_padding: impl Into<EdgeInsetsGeometry>,
) -> MaterialBanner
pub fn leading_padding( self, leading_padding: impl Into<EdgeInsetsGeometry>, ) -> MaterialBanner
Dart MaterialBanner(leadingPadding:).
Sourcepub fn force_actions_below(self, force_actions_below: bool) -> MaterialBanner
pub fn force_actions_below(self, force_actions_below: bool) -> MaterialBanner
Dart MaterialBanner(forceActionsBelow:).
Sourcepub fn overflow_alignment(
self,
overflow_alignment: OverflowBarAlignment,
) -> MaterialBanner
pub fn overflow_alignment( self, overflow_alignment: OverflowBarAlignment, ) -> MaterialBanner
Dart MaterialBanner(overflowAlignment:).
Sourcepub fn animation(self, animation: AnimationRef<f64>) -> MaterialBanner
pub fn animation(self, animation: AnimationRef<f64>) -> MaterialBanner
Dart MaterialBanner(animation:).
Sourcepub fn on_visible(
self,
on_visible: impl Fn(&mut App) + 'static,
) -> MaterialBanner
pub fn on_visible( self, on_visible: impl Fn(&mut App) + 'static, ) -> MaterialBanner
Dart MaterialBanner(onVisible:).
Sourcepub fn create_animation_controller(
app: &mut App,
vsync: impl TickerProvider,
) -> Ref<AnimationController>
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.
Sourcepub fn with_animation(
&self,
new_animation: AnimationRef<f64>,
fallback_key: Option<KeyRef>,
) -> MaterialBanner
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
impl Clone for MaterialBanner
Source§impl Debug for MaterialBanner
impl Debug for MaterialBanner
Source§impl StatefulWidget for MaterialBanner
impl StatefulWidget for MaterialBanner
Source§type State = MaterialBannerState
type State = MaterialBannerState
Source§fn create_state(&self) -> MaterialBannerState
fn create_state(&self) -> MaterialBannerState
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
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 MaterialBannerwhere
*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
impl UnsafeUnpin for MaterialBannerwhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.