showSnackBar method

void showSnackBar(
  1. String message, {
  2. Duration duration = const Duration(seconds: 3),
  3. SnackBarAction? action,
  4. Color? backgroundColor,
  5. Color? textColor,
})

Shows a snackbar with the given message.

Example:

context.showSnackBar('Hello!');
context.showSnackBar('Hello!', duration: Duration(seconds: 5));

Implementation

void showSnackBar(
  String message, {
  Duration duration = const Duration(seconds: 3),
  SnackBarAction? action,
  Color? backgroundColor,
  Color? textColor,
}) {
  ScaffoldMessenger.of(this).showSnackBar(
    SnackBar(
      content: Text(message, style: textColor != null ? TextStyle(color: textColor) : null),
      duration: duration,
      action: action,
      backgroundColor: backgroundColor,
    ),
  );
}