show static method
void
show(
- String text, {
- BuildContext? context,
- Duration duration = const Duration(seconds: 2),
- DraftModeUIToastStyle style = DraftModeUIToastStyle.notice,
Displays a toast with the given text.
An explicit context can be provided; when omitted the method falls back
to the navigator registered via DraftModeUIContext.init. The toast fades
out automatically after duration (defaults to 2 seconds). If a toast is
already showing it is removed first.
Implementation
static void show(
String text, {
BuildContext? context,
Duration duration = const Duration(seconds: 2),
DraftModeUIToastStyle style = DraftModeUIToastStyle.notice,
}) {
_current?.remove();
_current = null;
final resolvedContext = DraftModeUIContext.buildContext(context);
final theme = DraftModeUITheme.maybeOf(resolvedContext);
final platformStyle = DraftModeUIPlatform.resolveStyle(resolvedContext);
final colors = _resolveColors(style, theme, platformStyle);
final overlay = Navigator.of(resolvedContext).overlay!;
final entry = OverlayEntry(
builder: (_) => _DraftModeUIToastWidget(
text: text,
duration: duration,
colors: colors,
radiusPill: theme?.radiusPill ?? 20,
fontSizeSecondary: theme?.fontSizeSecondary ?? 15,
fontWeightMedium: theme?.fontWeightMedium ?? FontWeight.w500,
bottomOffset: theme?.toastBottomOffset ?? 80,
opacity: theme?.toastOpacity ?? 0.9,
maxWidth: theme?.toastMaxWidth ?? 420,
horizontalInset: theme?.toastHorizontalInset ?? 16,
radius: theme?.toastRadius ?? 20,
minHeight: theme?.toastMinHeight ?? 44,
paddingHorizontal: theme?.toastPaddingHorizontal ?? 16,
paddingVertical: theme?.toastPaddingVertical ?? 8,
shadowColor: theme?.toastShadowColor ?? const Color(0x1F000000),
shadowBlurRadius: theme?.toastShadowBlurRadius ?? 12,
animationDuration: theme?.animationDurationDefault ??
const Duration(milliseconds: 250),
animationCurve: theme?.animationCurve ?? Curves.easeInOut,
platformStyle: platformStyle,
onDismissed: () {
_current?.remove();
_current = null;
},
),
);
_current = entry;
overlay.insert(entry);
}