toast static method
Future<void>
toast(
- String message, {
- ToastPosition position = ToastPosition.bottom,
- ToastType type = ToastType.scale,
- Duration duration = const Duration(milliseconds: 2500),
- Duration? delay,
- IconData? icon,
- Color? color,
- bool lastToastShownAt = false,
- Offset? customOffset,
- Widget? child,
})
Implementation
static Future<void> toast(
String message, {
ToastPosition position = ToastPosition.bottom,
ToastType type = ToastType.scale,
Duration duration = const Duration(milliseconds: 2500),
Duration? delay,
IconData? icon,
Color? color,
bool lastToastShownAt = false,
Offset? customOffset,
Widget? child
}) async {
if(delay != null) {
await Future.delayed(delay);
}
if(lastToastShownAt) {
if (_isShowing) return;
}
_isShowing = true;
final overlay = NavigationService.defaultKey.currentState?.overlay;
if (overlay == null) {
_isShowing = false;
return;
}
late OverlayEntry overlayEntry;
overlayEntry = OverlayEntry(
builder: (_) => AnimatedSnackbar(
message: message,
position: position,
type: type,
icon: icon,
color: color,
duration: duration,
customOffset: customOffset,
child: child,
onClose: () {
// remove safely
if (overlayEntry.mounted) overlayEntry.remove();
_isShowing = false;
},
),
);
overlay.insert(overlayEntry);
}