toast static method
void
toast({
- required String message,
- Duration duration = const Duration(seconds: 2),
- Color? backgroundColor,
- Color? textColor,
- double borderRadius = 20,
- EdgeInsets padding = const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
- EdgeInsets margin = const EdgeInsets.only(bottom: 30),
- VoidCallback? onDismiss,
Floating toast-style notification
Implementation
static void toast({
required String message,
Duration duration = const Duration(seconds: 2),
Color? backgroundColor,
Color? textColor,
double borderRadius = 20,
EdgeInsets padding = const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
EdgeInsets margin = const EdgeInsets.only(bottom: 30),
VoidCallback? onDismiss,
}) =>
ScaffoldMessenger.of(navigatorKey.currentContext!)
.showSnackBar(SnackBar(
content: Text(
message,
style: TextStyle(color: textColor ?? theme.colorScheme.onSurface),
textAlign: TextAlign.center,
),
backgroundColor: backgroundColor ?? theme.colorScheme.surface,
elevation: 6,
duration: duration,
behavior: SnackBarBehavior.floating,
margin: margin,
padding: padding,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(borderRadius),
),
))
.closed
.then((_) {
onDismiss?.call();
});