StreamSnackbarMessenger class

Imperative owner of a snackbar queue.

One StreamSnackbarMessenger backs one rendering surface: hand it to a StreamSnackbarHost or StreamSnackbarPopup and call show to enqueue. If another snackbar is already visible, the new call waits its turn behind it.

Dispose when no longer needed.

{@tool snippet}

Manual ownership:

final messenger = StreamSnackbarMessenger();
final controller = messenger.show(const StreamSnackbar(
  message: Text('Message deleted'),
  variant: StreamSnackbarVariant.success,
  action: StreamSnackbarAction(label: Text('Undo'), onPressed: undo),
));

{@end-tool}

See also:

Inheritance

Constructors

StreamSnackbarMessenger()
Creates an empty messenger.

Properties

currentController StreamSnackbarController?
The controller for the currently-displayed snackbar, or null if none.
no setter
currentSnackbar StreamSnackbar?
The StreamSnackbar currently being displayed, or null if none.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
clearSnackbars() → void
Removes every snackbar — current and queued — without animation.
dispose() → void
Discards any resources used by the object.
override
hideCurrent([StreamSnackbarClosedReason reason = .dismiss]) → void
Dismisses the currently-displayed snackbar with the exit animation. No-op when the queue is empty.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeCurrent([StreamSnackbarClosedReason reason = .remove]) → void
Dismisses the currently-displayed snackbar without an exit animation and immediately advances to the next queued one. No-op when the queue is empty.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
show(StreamSnackbar snackbar, {bool replace = false}) StreamSnackbarController
Enqueues snackbar for display.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

maybeOf(BuildContext context) StreamSnackbarMessenger?
Returns the nearest StreamSnackbarMessenger ancestor, or null if none is found.
of(BuildContext context) StreamSnackbarMessenger
Returns the nearest StreamSnackbarMessenger ancestor provided by a StreamSnackbarHost, StreamSnackbarPopup, or StreamSnackbarScope.