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 colors = _resolveColors(style, theme);
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,
spacingLarge: theme?.spacingLarge ?? 20,
spacingTertiary: theme?.spacingTertiary ?? 10,
bottomOffset: theme?.toastBottomOffset ?? 80,
opacity: theme?.toastOpacity ?? 0.9,
animationDuration: theme?.animationDurationDefault ??
const Duration(milliseconds: 250),
animationCurve: theme?.animationCurve ?? Curves.easeInOut,
onDismissed: () {
_current?.remove();
_current = null;
},
),
);
_current = entry;
overlay.insert(entry);
}