showToast method

void showToast({
  1. required String text,
  2. Duration? duration,
  3. SnackBarAction? action,
  4. TextStyle? textStyle,
  5. Color? backgroundColor,
  6. SnackBarBehavior? behavior,
  7. bool hideCurrentSnackbar = true,
})

Shows a SnackBar across all registered Scaffolds but instead of SnackBar widget, you can just give it a string.

Implementation

void showToast({
  required String text,
  Duration? duration,
  SnackBarAction? action,
  TextStyle? textStyle,
  Color? backgroundColor,
  SnackBarBehavior? behavior,
  bool hideCurrentSnackbar = true,
}) {
  if (hideCurrentSnackbar) {
    ScaffoldMessenger.of(this).hideCurrentSnackBar();
  }
  ScaffoldMessenger.of(this).showSnackBar(
    SnackBar(
      content: Text(
        text,
        style: textStyle,
      ),
      backgroundColor: backgroundColor,
      duration: duration ?? const Duration(seconds: 5),
      action: action,
      behavior: behavior,
    ),
  );
}