pub struct SnackBar {Show 20 fields
pub key: Option<KeyRef>,
pub content: WidgetRef,
pub background_color: Option<Color>,
pub elevation: Option<f64>,
pub margin: Option<EdgeInsetsGeometry>,
pub padding: Option<EdgeInsetsGeometry>,
pub width: Option<f64>,
pub shape: Option<ShapeBorderRef>,
pub hit_test_behavior: Option<HitTestBehavior>,
pub behavior: Option<SnackBarBehavior>,
pub action: Option<SnackBarAction>,
pub action_overflow_threshold: Option<f64>,
pub show_close_icon: Option<bool>,
pub close_icon_color: Option<AnyColor>,
pub duration: Duration,
pub persist: Option<bool>,
pub animation: Option<AnimationRef<f64>>,
pub on_visible: Option<VoidCallback>,
pub dismiss_direction: Option<DismissDirection>,
pub clip_behavior: Clip,
}Expand description
A lightweight message with an optional action which briefly displays at the bottom of the screen.
Learn more about SnackBar on the Flutter YouTube channel.
To display a snack bar, call ScaffoldMessenger::of(app, context).show_snack_bar(..),
passing an instance of SnackBar that describes the message.
To control how long the SnackBar remains visible, specify a
duration.
A SnackBar with an action will not time out when TalkBack or VoiceOver are
enabled. This is controlled by AccessibilityFeatures.accessibleNavigation.
During page transitions, the SnackBar will smoothly animate to its
location on the other page. For example if the SnackBar::behavior is set to
SnackBarBehavior::Floating and the next page has a floating action button,
while the current one does not, the SnackBar will smoothly animate above
the floating action button. It also works in the case of a back gesture
transition.
See also:
ScaffoldMessenger::of, to obtain the currentScaffoldMessengerState, which manages the display and animation of snack bars.ScaffoldMessengerState::show_snack_bar, which displays aSnackBar.ScaffoldMessengerState::remove_current_snack_bar, which abruptly hides the currently displayed snack bar, if any, and allows the next to be displayed.SnackBarAction, which is used to specify anactionbutton to show on the snack bar.SnackBarThemeData, to configure the default property values forSnackBarwidgets.- https://material.io/design/components/snackbars.html
Fields§
§key: Option<KeyRef>§content: WidgetRefThe primary content of the snack bar.
Typically a Text widget.
background_color: Option<Color>The snack bar’s background color.
If not specified, the ambient SnackBarThemeData::background_color is used.
If that is not specified it will default to a
dark variation of ColorScheme.surface for light themes, or
ColorScheme.onSurface for dark themes.
elevation: Option<f64>The z-coordinate at which to place the snack bar. This controls the size of the shadow below the snack bar.
Defines the card’s Material.elevation.
If this property is null, then the ambient SnackBarThemeData::elevation
is used, if that is also null, the default value is 6.0.
margin: Option<EdgeInsetsGeometry>Empty space to surround the snack bar.
This property is only used when behavior is
SnackBarBehavior::Floating. It can not be used if width is
specified.
If this property is null, then the ambient SnackBarThemeData::inset_padding
is used. If that is also null, then the default is
EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 10.0).
If this property is not null and hit_test_behavior is
null, then hit_test_behavior default is
HitTestBehavior::DeferToChild.
padding: Option<EdgeInsetsGeometry>The amount of padding to apply to the snack bar’s content and optional action.
If this property is null, the default padding values are as follows:
content- Top and bottom paddings are 14.
- Left padding is 24 if
behaviorisSnackBarBehavior::Fixed, 16 ifbehaviorisSnackBarBehavior::Floating. - Right padding is same as start padding if there is no
action, otherwise 0.
action- Top and bottom paddings are 14.
- Left and right paddings are half of
content’s left padding.
If this property is not null, the padding is as follows:
content- Left, top and bottom paddings are assigned normally.
- Right padding is assigned normally if there is no
action, otherwise 0.
action- Left padding is replaced with half the right padding.
- Top and bottom paddings are assigned normally.
- Right padding is replaced with one and a half times the right padding.
width: Option<f64>The width of the snack bar.
If width is specified, the snack bar will be centered horizontally in the
available space. This property is only used when behavior is
SnackBarBehavior::Floating. It can not be used if margin is
specified.
If this property is null, then the ambient SnackBarThemeData::width
is used. If that is null, the snack bar will take up the full device
width less the margin.
shape: Option<ShapeBorderRef>The shape of the snack bar’s Material.
Defines the snack bar’s Material.shape.
If this property is null, then the ambient SnackBarThemeData::shape
is used. If that’s null then the shape will
depend on the SnackBarBehavior. For SnackBarBehavior::Fixed, no
overriding shape is specified, so the SnackBar is rectangular. For
SnackBarBehavior::Floating, it uses a RoundedRectangleBorder with a
circular corner radius of 4.0.
hit_test_behavior: Option<HitTestBehavior>Defines how the snack bar area, including margin, will behave during hit testing.
If this property is null, and margin is not null or the ambient
SnackBarThemeData::inset_padding is not null, then
HitTestBehavior::DeferToChild is used by default.
Please refer to HitTestBehavior for a detailed explanation of every behavior.
behavior: Option<SnackBarBehavior>This defines the behavior and location of the snack bar.
Defines where a SnackBar should appear within a Scaffold and how its
location should be adjusted when the scaffold also includes a
FloatingActionButton or a BottomNavigationBar
If this property is null, then the ambient SnackBarThemeData::behavior
is used. If that is null, then the default is SnackBarBehavior::Fixed.
If this value is SnackBarBehavior::Floating, the length of the bar
is defined by either width or margin.
action: Option<SnackBarAction>(optional) An action that the user can take based on the snack bar.
For example, the snack bar might let the user undo the operation that prompted the snackbar. Snack bars can have at most one action.
The action should not be “dismiss” or “cancel”.
action_overflow_threshold: Option<f64>(optional) The percentage threshold for action widget’s width before it overflows to a new line.
Must be between 0 and 1.
If the width of the action divided by the total snackbar width
is greater than this percentage, the action will appear below the
content.
At a value of 0, the action will always overflow to a new line.
Defaults to 0.25.
show_close_icon: Option<bool>(optional) Whether to include a “close” icon widget.
Tapping the icon will close the snack bar.
close_icon_color: Option<AnyColor>An optional color for the close icon, if show_close_icon
is true.
If this property is null, then the ambient SnackBarThemeData::close_icon_color
is used. If that is null, then the default is inverse surface.
If close_icon_color is a WidgetStateColor, then the
icon color will be resolved against the set of WidgetStates that the action text
is in, thus allowing for different colors for states such as pressed,
hovered and others.
duration: DurationThe amount of time the snack bar should be displayed.
Defaults to 4.0s.
See also:
ScaffoldMessengerState::remove_current_snack_bar, which abruptly hides the currently displayed snack bar, if any, and allows the next to be displayed.- https://material.io/design/components/snackbars.html
persist: Option<bool>Whether the snack bar will stay or auto-dismiss after timeout, as given; read
effective_persist.
If true, the snack bar remains visible even after the timeout, until the user taps the action button or the close icon.
If false, the snack bar will be dismissed after the timeout.
If not provided, but the snackbar action is not null, the snackbar will persist as well.
animation: Option<AnimationRef<f64>>The animation driving the entrance and exit of the snack bar.
on_visible: Option<VoidCallback>Called the first time that the snackbar is visible within a Scaffold.
When multiple Scaffolds are registered to the same ScaffoldMessengerState,
on_visible is called once for each scaffold.
See also:
ScaffoldMessenger, which managesSnackBars forScaffolddescendants.
dismiss_direction: Option<DismissDirection>The direction in which the SnackBar can be dismissed.
If this property is null, then the ambient SnackBarThemeData::dismiss_direction
is used. If that is null, then the default is DismissDirection::Down.
clip_behavior: ClipThe content will be clipped (or not) according to this option.
See the enum Clip for details of all possible options and their common use cases.
Defaults to Clip::HardEdge.
Implementations§
Source§impl SnackBar
impl SnackBar
Sourcepub fn new<K>(content: impl IntoWidget<K>) -> SnackBar
pub fn new<K>(content: impl IntoWidget<K>) -> SnackBar
Creates a snack bar; Dart’s optional arguments are the setters.
The elevation must be null or non-negative.
Sourcepub fn background_color(self, background_color: Color) -> SnackBar
pub fn background_color(self, background_color: Color) -> SnackBar
Dart SnackBar(backgroundColor:).
Sourcepub fn margin(self, margin: impl Into<EdgeInsetsGeometry>) -> SnackBar
pub fn margin(self, margin: impl Into<EdgeInsetsGeometry>) -> SnackBar
Dart SnackBar(margin:).
Sourcepub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> SnackBar
pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> SnackBar
Dart SnackBar(padding:).
Sourcepub fn shape(self, shape: impl Into<ShapeBorderRef>) -> SnackBar
pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> SnackBar
Dart SnackBar(shape:).
Sourcepub fn hit_test_behavior(self, hit_test_behavior: HitTestBehavior) -> SnackBar
pub fn hit_test_behavior(self, hit_test_behavior: HitTestBehavior) -> SnackBar
Dart SnackBar(hitTestBehavior:).
Sourcepub fn behavior(self, behavior: SnackBarBehavior) -> SnackBar
pub fn behavior(self, behavior: SnackBarBehavior) -> SnackBar
Dart SnackBar(behavior:).
Sourcepub fn action(self, action: SnackBarAction) -> SnackBar
pub fn action(self, action: SnackBarAction) -> SnackBar
Dart SnackBar(action:).
Sourcepub fn action_overflow_threshold(
self,
action_overflow_threshold: f64,
) -> SnackBar
pub fn action_overflow_threshold( self, action_overflow_threshold: f64, ) -> SnackBar
Dart SnackBar(actionOverflowThreshold:).
Sourcepub fn show_close_icon(self, show_close_icon: bool) -> SnackBar
pub fn show_close_icon(self, show_close_icon: bool) -> SnackBar
Dart SnackBar(showCloseIcon:).
Sourcepub fn close_icon_color(self, close_icon_color: impl Into<AnyColor>) -> SnackBar
pub fn close_icon_color(self, close_icon_color: impl Into<AnyColor>) -> SnackBar
Dart SnackBar(closeIconColor:).
Sourcepub fn animation(self, animation: AnimationRef<f64>) -> SnackBar
pub fn animation(self, animation: AnimationRef<f64>) -> SnackBar
Dart SnackBar(animation:).
Sourcepub fn on_visible(self, on_visible: impl Fn(&mut App) + 'static) -> SnackBar
pub fn on_visible(self, on_visible: impl Fn(&mut App) + 'static) -> SnackBar
Dart SnackBar(onVisible:).
Sourcepub fn dismiss_direction(self, dismiss_direction: DismissDirection) -> SnackBar
pub fn dismiss_direction(self, dismiss_direction: DismissDirection) -> SnackBar
Dart SnackBar(dismissDirection:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> SnackBar
pub fn clip_behavior(self, clip_behavior: Clip) -> SnackBar
Dart SnackBar(clipBehavior:).
Sourcepub fn effective_persist(&self) -> bool
pub fn effective_persist(&self) -> bool
Dart’s persist field, as its constructor fills it: persist ?? action != null.
Sourcepub fn create_animation_controller(
app: &mut App,
vsync: impl TickerProvider,
duration: Option<Duration>,
reverse_duration: Option<Duration>,
) -> Ref<AnimationController>
pub fn create_animation_controller( app: &mut App, vsync: impl TickerProvider, duration: Option<Duration>, reverse_duration: Option<Duration>, ) -> Ref<AnimationController>
Creates an animation controller useful for driving a snack bar’s entrance and exit animation.
Sourcepub fn with_animation(
&self,
new_animation: AnimationRef<f64>,
fallback_key: Option<KeyRef>,
) -> SnackBar
pub fn with_animation( &self, new_animation: AnimationRef<f64>, fallback_key: Option<KeyRef>, ) -> SnackBar
Creates a copy of this snack bar but with the animation replaced with the given animation.
If the original snack bar lacks a key, the newly created snack bar will use the given fallback key.
Trait Implementations§
Source§impl StatefulWidget for SnackBar
impl StatefulWidget for SnackBar
Source§type State = SnackBarState
type State = SnackBarState
Source§fn create_state(&self) -> SnackBarState
fn create_state(&self) -> SnackBarState
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 SnackBar
impl !Send for SnackBar
impl !Sync for SnackBar
impl !UnwindSafe for SnackBar
impl Forget for SnackBar
impl Freeze for SnackBarwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
*const RcInner<dyn ShapeBorder> is !null: Freeze,
PhantomData<RcInner<dyn ShapeBorder>>: 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,
*const RcInner<dyn Fn(&mut App)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze,
NonZero<u32>: Freeze,
&'static AnimationVTable<f64>: Freeze,
*const RcInner<Keep> is !null: Freeze,
PhantomData<RcInner<Keep>>: Freeze,
impl Move for SnackBar
impl Unpin for SnackBar
impl UnsafeUnpin for SnackBarwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
*const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn ShapeBorder>>: 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,
*const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
&'static AnimationVTable<f64>: UnsafeUnpin,
*const RcInner<Keep> is !null: UnsafeUnpin,
PhantomData<RcInner<Keep>>: 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.