toast static method

void toast({
  1. required String message,
  2. Duration duration = const Duration(seconds: 2),
  3. Color? backgroundColor,
  4. Color? textColor,
  5. double borderRadius = 20,
  6. EdgeInsets padding = const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
  7. EdgeInsets margin = const EdgeInsets.only(bottom: 30),
  8. 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();
    });