showSnackbar function

void showSnackbar(
  1. BuildContext context,
  2. String message, {
  3. Duration duration = const Duration(seconds: 3),
})

Displays a snackbar with a custom message in the provided context.

The snackbar has a floating behavior and a customizable display duration.

Parameters:

  • context (BuildContext): The context in which to display the snackbar.
  • message (String): The message to display in the snackbar.
  • duration (Duration): The duration for which the snackbar should be displayed. Defaults to 3 seconds.

Implementation

void showSnackbar(BuildContext context, String message,
    {Duration duration = const Duration(seconds: 3)}) {
  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(
      content: Text(message),
      duration: duration,
      behavior: SnackBarBehavior.floating,
    ),
  );
}