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
impl ScaffoldMessengerState
Sourcepub fn show_snack_bar(
self: Handle<Self>,
app: &mut App,
snack_bar: SnackBar,
snack_bar_animation_style: Option<AnimationStyle>,
) -> Rc<ScaffoldFeatureController<SnackBar, SnackBarClosedReason>>
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().
Sourcepub fn remove_current_snack_bar(
self: Handle<Self>,
app: &mut App,
reason: SnackBarClosedReason,
)
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.
Sourcepub fn hide_current_snack_bar(
self: Handle<Self>,
app: &mut App,
reason: SnackBarClosedReason,
)
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.
Sourcepub fn clear_snack_bars(self: Handle<Self>, app: &mut App)
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.
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.
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.
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.
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
impl State for ScaffoldMessengerState
Source§type Widget = ScaffoldMessenger
type Widget = ScaffoldMessenger
State<T> type argument.Source§fn state_data(self: Handle<Self>, app: &App) -> &StateData<Self::Widget>
fn state_data(self: Handle<Self>, app: &App) -> &StateData<Self::Widget>
state
(state_accessors!).Source§fn state_data_mut(
self: Handle<Self>,
app: &mut App,
) -> &mut StateData<Self::Widget>
fn state_data_mut( self: Handle<Self>, app: &mut App, ) -> &mut StateData<Self::Widget>
state_data.Source§fn did_change_dependencies(self: Handle<Self>, app: &mut App)
fn did_change_dependencies(self: Handle<Self>, app: &mut App)
Source§fn activate(self: Handle<Self>, app: &mut App)
fn activate(self: Handle<Self>, app: &mut App)
deactivate. Read moreSource§fn build(self: Handle<Self>, app: &mut App, context: BuildContext) -> WidgetRef
fn build(self: Handle<Self>, app: &mut App, context: BuildContext) -> WidgetRef
Source§fn dispose(self: Handle<Self>, app: &mut App)
fn dispose(self: Handle<Self>, app: &mut App)
Source§fn widget(self: Handle<Self>, app: &App) -> &Self::Widget
fn widget(self: Handle<Self>, app: &App) -> &Self::Widget
Source§fn context(self: Handle<Self>, app: &App) -> AnyElement
fn context(self: Handle<Self>, app: &App) -> AnyElement
Source§fn init_state(self: Handle<Self>, app: &mut App)
fn init_state(self: Handle<Self>, app: &mut App)
Source§fn did_update_widget(
self: Handle<Self>,
app: &mut App,
old_widget: &Self::Widget,
)
fn did_update_widget( self: Handle<Self>, app: &mut App, old_widget: &Self::Widget, )
Source§fn set_state(self: Handle<Self>, app: &mut App, f: impl FnOnce(&mut Self))
fn set_state(self: Handle<Self>, app: &mut App, f: impl FnOnce(&mut Self))
Source§fn deactivate(self: Handle<Self>, app: &mut App)
fn deactivate(self: Handle<Self>, app: &mut App)
Source§fn debug_fill_properties(
self: Handle<Self>,
app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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.
impl TickerProviderObject for ScaffoldMessengerState
Dart’s vsync: this.
Source§fn create_ticker(
self: Handle<Self>,
app: &mut App,
on_tick: TickerCallback,
) -> Ref<Ticker>
fn create_ticker( self: Handle<Self>, app: &mut App, on_tick: TickerCallback, ) -> Ref<Ticker>
Source§impl TickerProviderStateMixin for ScaffoldMessengerState
impl TickerProviderStateMixin for ScaffoldMessengerState
Source§fn ticker_provider_data(
self: Handle<Self>,
app: &App,
) -> &TickerProviderStateMixinData
fn ticker_provider_data( self: Handle<Self>, app: &App, ) -> &TickerProviderStateMixinData
Source§fn ticker_provider_data_mut(
self: Handle<Self>,
app: &mut App,
) -> &mut TickerProviderStateMixinData
fn ticker_provider_data_mut( self: Handle<Self>, app: &mut App, ) -> &mut TickerProviderStateMixinData
ticker_provider_data.Source§fn debug_fill_properties(
self: Handle<Self>,
app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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>>
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.