show method
void
show(
- String text, {
- ToastType type = ToastType.success,
- ToastDurationType durationType = ToastDurationType.short,
- Icon? icon,
Displays a toast with the given text.
Optional parameters:
type: Determines icon and color styling. Default is ToastType.success.durationType: Determines how long the toast stays visible.icon: Custom icon. If null, a default icon is used based ontype.
If another toast is already visible, this call will be ignored.
Implementation
void show(
String text, {
ToastType type = ToastType.success,
ToastDurationType durationType = ToastDurationType.short,
Icon? icon,
}) {
if (!_context.mounted) return;
final overlay = Overlay.maybeOf(_context);
if (overlay == null) return;
// Prevent showing multiple toasts at once.
if (_currentToast != null) return;
_currentToast = this;
_overlayEntry = OverlayEntry(
builder: (context) => Positioned(
bottom: 40,
left: 20,
right: 20,
child: Material(
color: Colors.transparent,
child: _buildToastContent(context, text, type, durationType, icon),
),
),
);
overlay.insert(_overlayEntry!);
Future.delayed(
Duration(seconds: durationType == ToastDurationType.short ? 4 : 8),
_removeToast,
);
}