Skip to main content

ScaffoldMessengerState

Struct ScaffoldMessengerState 

Source
pub struct ScaffoldMessengerState { /* private fields */ }
Expand description

State for a ScaffoldMessenger.

A ScaffoldMessengerState object can be used to show_snack_bar or show_material_banner for every registered Scaffold that is a descendant of the associated ScaffoldMessenger. Scaffolds will register to receive SnackBars and MaterialBanners from their closest ScaffoldMessenger ancestor.

Typically obtained via ScaffoldMessenger::of.

Implementations§

Source§

impl ScaffoldMessengerState

Source

pub fn show_snack_bar( self: Handle<Self>, app: &mut App, snack_bar: SnackBar, snack_bar_animation_style: Option<AnimationStyle>, ) -> Rc<ScaffoldFeatureController<SnackBar, SnackBarClosedReason>>

Shows a SnackBar across all registered Scaffolds. Scaffolds register to receive snack bars from their closest ScaffoldMessenger ancestor. If there are several registered scaffolds the snack bar is shown simultaneously on all of them.

A scaffold can show at most one snack bar at a time. If this function is called while another snack bar is already visible, the given snack bar will be added to a queue and displayed after the earlier snack bars have closed.

To control how long a SnackBar remains visible, use SnackBar::duration.

To remove the SnackBar with an exit animation, use hide_current_snack_bar or call ScaffoldFeatureController::close on the returned ScaffoldFeatureController. To remove a SnackBar suddenly (without an animation), use remove_current_snack_bar.

See ScaffoldMessenger::of for information about how to obtain the ScaffoldMessengerState.

§Relative positioning of floating SnackBars

A SnackBar with SnackBar::behavior set to SnackBarBehavior::Floating is positioned above the widgets provided to Scaffold::floating_action_button, Scaffold::persistent_footer_buttons, and Scaffold::bottom_navigation_bar. If some or all of these widgets take up enough space such that the SnackBar would not be visible when positioned above them, an error will be thrown. In this case, consider constraining the size of these widgets to allow room for the SnackBar to be visible.

If AnimationStyle::duration is provided in the snack_bar_animation_style parameter, it will be used to override the snackbar show animation duration. Otherwise, defaults to 250ms.

If AnimationStyle::reverse_duration is provided in the snack_bar_animation_style parameter, it will be used to override the snackbar hide animation duration. Otherwise, defaults to 250ms.

To disable the snackbar animation, use AnimationStyle::no_animation().

Source

pub fn remove_current_snack_bar( self: Handle<Self>, app: &mut App, reason: SnackBarClosedReason, )

Removes the current SnackBar (if any) immediately from registered Scaffolds.

The removed snack bar does not run its normal exit animation. If there are any queued snack bars, they begin their entrance animation immediately.

Dart’s default reason is SnackBarClosedReason::Remove.

Source

pub fn hide_current_snack_bar( self: Handle<Self>, app: &mut App, reason: SnackBarClosedReason, )

Removes the current SnackBar by running its normal exit animation.

The closed completer is called after the animation is complete.

Dart’s default reason is SnackBarClosedReason::Hide.

Source

pub fn clear_snack_bars(self: Handle<Self>, app: &mut App)

Removes all the snackBars currently in queue by clearing the queue and running normal exit animation on the current snackBar.

Source

pub fn show_material_banner( self: Handle<Self>, app: &mut App, material_banner: MaterialBanner, ) -> Rc<ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason>>

Shows a MaterialBanner across all registered Scaffolds. Scaffolds register to receive material banners from their closest ScaffoldMessenger ancestor. If there are several registered scaffolds the material banner is shown simultaneously on all of them.

A scaffold can show at most one material banner at a time. If this function is called while another material banner is already visible, the given material banner will be added to a queue and displayed after the earlier material banners have closed.

To remove the MaterialBanner with an exit animation, use hide_current_material_banner or call ScaffoldFeatureController::close on the returned ScaffoldFeatureController. To remove a MaterialBanner suddenly (without an animation), use remove_current_material_banner.

When this ScaffoldMessenger is above the Navigator, such as the one created by MaterialApp, a MaterialBanner stays visible after the route that showed it is popped, and that route’s BuildContext is deactivated. Because of this, callbacks in MaterialBanner::actions should not call ScaffoldMessenger::of with a BuildContext from the route that showed the banner. Instead, wrap the action widget in a Builder to obtain an active BuildContext, or save the ScaffoldMessengerState reference before calling show_material_banner.

See ScaffoldMessenger::of for information about how to obtain the ScaffoldMessengerState.

Source

pub fn remove_current_material_banner( self: Handle<Self>, app: &mut App, reason: MaterialBannerClosedReason, )

Removes the current MaterialBanner (if any) immediately from registered Scaffolds.

The removed material banner does not run its normal exit animation. If there are any queued material banners, they begin their entrance animation immediately.

Dart’s default reason is MaterialBannerClosedReason::Remove.

Source

pub fn hide_current_material_banner( self: Handle<Self>, app: &mut App, reason: MaterialBannerClosedReason, )

Removes the current MaterialBanner by running its normal exit animation.

The closed completer is called after the animation is complete.

Dart’s default reason is MaterialBannerClosedReason::Hide.

Source

pub fn clear_material_banners(self: Handle<Self>, app: &mut App)

Removes all the MaterialBanners currently in queue by clearing the queue and running normal exit animation on the current MaterialBanner.

Trait Implementations§

Source§

impl State for ScaffoldMessengerState

Source§

type Widget = ScaffoldMessenger

The widget this state belongs to; Dart’s State<T> type argument.
Source§

fn state_data(self: Handle<Self>, app: &App) -> &StateData<Self::Widget>

The framework’s bookkeeping, held under the field state (state_accessors!).
Source§

fn state_data_mut( self: Handle<Self>, app: &mut App, ) -> &mut StateData<Self::Widget>

Source§

fn did_change_dependencies(self: Handle<Self>, app: &mut App)

Called when a dependency of this State object changes. Read more
Source§

fn activate(self: Handle<Self>, app: &mut App)

Called when this object is reinserted into the tree after having been removed via deactivate. Read more
Source§

fn build(self: Handle<Self>, app: &mut App, context: BuildContext) -> WidgetRef

Describes the part of the user interface represented by this widget. Read more
Source§

fn dispose(self: Handle<Self>, app: &mut App)

Called when this object is removed from the tree permanently. Read more
Source§

fn widget(self: Handle<Self>, app: &App) -> &Self::Widget

The current configuration. Read more
Source§

fn context(self: Handle<Self>, app: &App) -> AnyElement

The location in the tree where this widget builds. Read more
Source§

fn mounted(self: Handle<Self>, app: &App) -> bool

Whether this State object is currently in a tree. Read more
Source§

fn init_state(self: Handle<Self>, app: &mut App)

Called when this object is inserted into the tree. Read more
Source§

fn did_update_widget( self: Handle<Self>, app: &mut App, old_widget: &Self::Widget, )

Called whenever the widget configuration changes. Read more
Source§

fn set_state(self: Handle<Self>, app: &mut App, f: impl FnOnce(&mut Self))

Notify the framework that the internal state of this object has changed. Read more
Source§

fn deactivate(self: Handle<Self>, app: &mut App)

Called when this object is removed from the tree. Read more
Source§

fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties this state shows where its element’s dump names it (state: ScrollableState#1a2b3(offset: 0.0)), after the lifecycle and mounting properties State’s base adds, which the framework adds first.
Source§

impl TickerProviderObject for ScaffoldMessengerState

Dart’s vsync: this.

Source§

impl TickerProviderStateMixin for ScaffoldMessengerState

Source§

fn ticker_provider_data( self: Handle<Self>, app: &App, ) -> &TickerProviderStateMixinData

Mixin field access.
Source§

fn ticker_provider_data_mut( self: Handle<Self>, app: &mut App, ) -> &mut TickerProviderStateMixinData

Source§

fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s TickerProviderStateMixin.debugFillProperties, which a state’s own body calls where Dart’s mixin adds its line.
Source§

fn create_ticker( self: Handle<Self>, app: &mut App, on_tick: FrameCallback, ) -> Retained<Handle<Ticker>>

TickerProvider::create_ticker: creates a ticker with the given callback.
Source§

fn activate(self: Handle<Self>, app: &mut App)

The mixin’s part of State::activate; the state calls it where Dart’s super.activate() would reach the mixin. A GlobalKey that moves the element to another view deactivates and activates it, so this is where the tickers follow it.
Source§

fn dispose(self: Handle<Self>, app: &mut App)

The mixin’s part of State::dispose; the state calls it where Dart’s super.dispose() would reach the mixin. Every vended ticker must already be disposed (by disposing its AnimationController).

Auto Trait Implementations§

§

impl !RefUnwindSafe for ScaffoldMessengerState

§

impl !Send for ScaffoldMessengerState

§

impl !Sync for ScaffoldMessengerState

§

impl !UnwindSafe for ScaffoldMessengerState

§

impl Forget for ScaffoldMessengerState

§

impl Freeze for ScaffoldMessengerState

§

impl Move for ScaffoldMessengerState

§

impl Unpin for ScaffoldMessengerState

§

impl UnsafeUnpin for ScaffoldMessengerState

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<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>