ShadToast class

A customizable toast notification widget.

The ShadToast widget displays a notification with a title, description, optional action, and close button, styled according to its variant (primary or destructive). It supports animations and integrates with ShadTheme for consistent appearance.

Inheritance
Available extensions

Constructors

ShadToast({Key? key, Object? id, Widget? title, Widget? description, Widget? action, Widget? closeIcon, IconData? closeIconData, Alignment? alignment, Offset? offset, Duration? duration, TextDirection? textDirection, List<Effect>? animateIn, List<Effect>? animateOut, CrossAxisAlignment? crossAxisAlignment, bool? showCloseIconOnlyWhenHovered, TextStyle? titleStyle, TextStyle? descriptionStyle, EdgeInsetsGeometry? actionPadding, ShadBorder? border, BorderRadius? radius, List<BoxShadow>? shadows, Color? backgroundColor, EdgeInsetsGeometry? padding, ShadPosition? closeIconPosition, BoxConstraints? constraints, MainAxisAlignment? mainAxisAlignment, MainAxisSize? mainAxisSize})
Creates a primary variant toast widget.
const
ShadToast.destructive({Key? key, Object? id, Widget? title, Widget? description, Widget? action, Widget? closeIcon, IconData? closeIconData, Alignment? alignment, Offset? offset, Duration? duration, TextDirection? textDirection, List<Effect>? animateIn, List<Effect>? animateOut, CrossAxisAlignment? crossAxisAlignment, bool? showCloseIconOnlyWhenHovered, TextStyle? titleStyle, TextStyle? descriptionStyle, EdgeInsetsGeometry? actionPadding, ShadBorder? border, BorderRadius? radius, List<BoxShadow>? shadows, Color? backgroundColor, EdgeInsetsGeometry? padding, ShadPosition? closeIconPosition, BoxConstraints? constraints, MainAxisAlignment? mainAxisAlignment, MainAxisSize? mainAxisSize})
Creates a destructive variant toast widget, typically for error or warning messages.
const
ShadToast.raw({Key? key, Object? id, required ShadToastVariant variant, Widget? title, Widget? description, Widget? action, Widget? closeIcon, IconData? closeIconData, Alignment? alignment, Offset? offset, Duration? duration, TextDirection? textDirection, List<Effect>? animateIn, List<Effect>? animateOut, CrossAxisAlignment? crossAxisAlignment, bool? showCloseIconOnlyWhenHovered, TextStyle? titleStyle, TextStyle? descriptionStyle, EdgeInsetsGeometry? actionPadding, ShadBorder? border, BorderRadius? radius, List<BoxShadow>? shadows, Color? backgroundColor, EdgeInsetsGeometry? padding, ShadPosition? closeIconPosition, BoxConstraints? constraints, MainAxisAlignment? mainAxisAlignment, MainAxisSize? mainAxisSize})
Creates a toast widget with a specified variant, offering full customization.
const

Properties

action Widget?
An optional action widget displayed alongside the content. Typically a button, padded according to actionPadding.
final
actionPadding EdgeInsetsGeometry?
The padding around the action widget. Defaults to start padding of 16 if not specified.
final
alignment Alignment?
The alignment of the toast within the screen. Defaults to Alignment.bottomRight if not specified.
final
animateIn List<Effect>?
The animation effects when the toast appears. Defaults to alignment-specific slide or fade effects if not specified.
final
animateOut List<Effect>?
The animation effects when the toast disappears. Defaults to alignment-specific slide or fade effects if not specified.
final
backgroundColor Color?
The background color of the toast. Defaults to the theme’s background color if not specified.
final
border ShadBorder?
The border surrounding the toast. Defaults to a border with the theme’s border color if not specified.
final
closeIcon Widget?
The custom widget for the close button. Overrides closeIconData if provided; defaults to a ghost button with an 'X' icon.
final
closeIconData IconData?
The icon data for the close button. Used if closeIcon is null; defaults to LucideIcons.x if not specified.
final
closeIconPosition ShadPosition?
The position of the close icon within the toast. Defaults to top-end (8, 8) if not specified.
final
constraints BoxConstraints?
Constraints applied to the toast’s layout. Responsive to screen size; defaults to unbounded min width and 420 max width on larger screens.
final
crossAxisAlignment CrossAxisAlignment?
The cross-axis alignment of the toast’s content (vertical). Defaults to CrossAxisAlignment.center if not specified.
final
description Widget?
The description widget displayed below the title. Typically a Text widget, styled with the theme’s muted style.
final
descriptionStyle TextStyle?
The text style for the description. Defaults to a muted style with variant-specific foreground color.
final
duration Duration?
The duration the toast remains visible before auto-hiding. Defaults to kDefaultToastDuration (5 seconds) if not specified.
final
hashCode int
The hash code for this object.
no setterinherited
id Object?
The unique identifier for the toast, used for tracking and managing toasts. Defaults to UniqueKey() if not specified.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
mainAxisAlignment MainAxisAlignment?
The main-axis alignment of the toast’s content (horizontally). Defaults to MainAxisAlignment.spaceBetween if not specified.
final
mainAxisSize MainAxisSize?
The main axis size of the toast's content (horizontal). Defaults to MainAxisSize.max if not specified.
final
offset Offset?
The offset from the alignment position as padding. Defaults to 16 pixels from edges or safe areas if not specified.
final
padding EdgeInsetsGeometry?
The padding inside the toast, surrounding all content.
final
radius BorderRadius?
The border radius of the toast’s corners. Defaults to the theme’s radius if not specified.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shadows List<BoxShadow>?
The list of box shadows applied to the toast for elevation. Defaults to large shadows if not specified.
final
showCloseIconOnlyWhenHovered bool?
Whether the close icon is visible only when the toast is hovered. Defaults to true if not specified.
final
textDirection TextDirection?
The directionality of the toast’s content (e.g., LTR or RTL). Defaults to null, inheriting from the context.
final
title Widget?
The title widget displayed at the top of the toast. Typically a Text widget, styled with the theme’s muted bold style.
final
titleStyle TextStyle?
The text style for the title. Defaults to a bold muted style with variant-specific foreground color.
final
variant ShadToastVariant
The variant of the toast, either ShadToastVariant.primary or ShadToastVariant.destructive. Determines the visual style applied through the ShadTheme.
final

Methods

animate({Key? key, List<Effect>? effects, AnimateCallback? onInit, AnimateCallback? onPlay, AnimateCallback? onComplete, bool? autoPlay, Duration? delay, AnimationController? controller, Adapter? adapter, double? target, double? value}) Animate

Available on Widget, provided by the AnimateWidgetExtensions extension

Wraps the target Widget in an Animate instance, and returns the instance for chaining calls. Ex. myWidget.animate() is equivalent to Animate(child: myWidget).
createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<ShadToast>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
positionedWith(ShadPosition position) Widget

Available on Widget, provided by the PositionedExt extension

toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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