Toast class

a data object for passing info into the toaster. the Toast is identified by id, which defaults to a random string, but may be set if the toast requires an ID that must be reused or memorized. type is a ToastType that tells the toaster how to style certain aspects of the toast; for instance, the icon on the toast. see ToastType for more details.

action.action is called only when the action text is tapped, not when the toast is dismissed; onDismiss is called when the action is tapped or when the toast is dismissed. in general, onDismiss can be used for resolving loading states, for example, when a toast is used to confirm that a user meant to tap a button. action.action is used to actually perform the action.

Toasts, by default, expire. This means that if a user does not interact with the toast, the toast will leave and trigger onDismiss. explicitly passing null to duration will cause the toast to force the user to dismiss it, else last forever.

Toast.completer may be used to create futures for if the user triggers the action; this is useful for situations where the UI must wait for an action to be taken, like updating loading spinners.

Constructors

Toast.new({String? id, required String message, required ToastType type, VoidCallback? onDismiss, Duration? duration = const Duration(seconds: 5), ToastAction? action})
Toast.completer({String? id, required String message, required ToastType type, required ToastAction action, Duration? duration = const Duration(seconds: 5), required Completer<bool> completer})

Properties

action ToastAction?
final
created DateTime
final
expireAt DateTime?
final
hashCode int
The hash code for this object.
no setteroverride
id String
final
message String
final
onDismiss VoidCallback?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type ToastType
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(covariant Toast other) bool
The equality operator.
override