showSnackBar static method

void showSnackBar({
  1. required String message,
  2. TextStyle messageStyle = const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
  3. bool isErrorMessage = false,
  4. Color backgroundColor = Colors.lightGreen,
  5. EdgeInsets margin = const EdgeInsets.all(0),
  6. EdgeInsets padding = const EdgeInsets.all(8),
  7. Duration duration = const Duration(milliseconds: 2000),
  8. SnackPosition snackPosition = SnackPosition.TOP,
  9. double borderRadius = 0,
  10. SnackStyle snackStyle = SnackStyle.GROUNDED,
})

Displays a snack bar with the specified parameters.

  • message: The message to display in the snack bar.
  • messageStyle: The TextStyle for the message text. Defaults to bold white text.
  • isErrorMessage: If true, the background color is set to red accent. Defaults to false.
  • backgroundColor: The background color of the snack bar. Defaults to Colors.lightGreen.
  • margin: The margin around the snack bar. Defaults to EdgeInsets.all(0).
  • padding: The padding inside the snack bar. Defaults to EdgeInsets.all(8).
  • duration: The duration the snack bar is visible. Defaults to 2000 milliseconds.
  • snackPosition: The position of the snack bar on the screen. Defaults to SnackPosition.TOP.
  • borderRadius: The border radius of the snack bar. Defaults to 0.
  • snackStyle: The style of the snack bar. Defaults to SnackStyle.GROUNDED.

Throws an Exception if GetMaterialApp is not used as the app's root widget.

Implementation

static void showSnackBar({
  required String message,
  TextStyle messageStyle = const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
  bool isErrorMessage = false,
  Color backgroundColor = Colors.lightGreen,
  EdgeInsets margin = const EdgeInsets.all(0),
  EdgeInsets padding = const EdgeInsets.all(8),
  Duration duration = const Duration(milliseconds: 2000),
  SnackPosition snackPosition = SnackPosition.TOP,
  double borderRadius = 0,
  SnackStyle snackStyle = SnackStyle.GROUNDED,
}) {
  try {
    Get.showSnackbar(
      GetSnackBar(
        messageText: Text(message, style: messageStyle),
        backgroundColor: isErrorMessage ? Colors.redAccent : backgroundColor,
        duration: duration,
        padding: padding,
        margin: margin,
        snackPosition: snackPosition,
        borderRadius: borderRadius,
        snackStyle: snackStyle,
      ),
    );
  } catch (e, s) {
    throw Exception("""
    \n🚨 Please wrap your 📱 App with GetMaterialApp ♺
    \nError Details:
    $e
    \nStack Trace:
    $s
    """);
  }
}