showFailureSnackBar static method

void showFailureSnackBar(
  1. String message, {
  2. String title = "",
  3. Function? onDismiss,
})

Displays an awesome-styled failure/error snackbar with optional dismiss callback.

Shows a visually rich error snackbar at the bottom of the screen using the AwesomeSnackbarContent widget. The snackbar automatically unfocuses active text fields and can trigger a callback when dismissed.

Parameters:

  • message: The error message to display (required, skips if empty)
  • title: Custom title (defaults to "Failure" if empty)
  • onDismiss: Optional callback function triggered when snackbar closes

The snackbar features:

  • Red background color (error theme)
  • Small font size from app theme
  • Bottom position with floating style
  • Smooth ease-in/ease-out animations
  • Duration from app constants (snackbarDuration)
  • Dismissible by user interaction

Example:

RtCommonFunction.showFailureSnackBar(
  'Failed to save data',
  title: 'Error',
  onDismiss: () => logError(),
);

See also:

Implementation

static void showFailureSnackBar(String message,
    {String title = "", Function? onDismiss}) {
  WidgetsBinding.instance.addPostFrameCallback((_) {
    if (message.trim().isEmpty) {
      return;
    }
    Get.focusScope?.unfocus();
    Get.snackbar(
        '', // Empty title to avoid displaying it twice
        '',
        titleText: Container(),
        messageText: AwesomeSnackbarContent(
          color: getBackgroundColor(ContentType.failure),
          inMaterialBanner: false,
          title: title.toString().isEmpty
              ? ContentType.failure.message.toString().capitalizeFirst!
              : title,
          message: message,
          messageFontSize: Utils.appFontFamily.textSmallestSize,
          contentType: ContentType.failure,
          showCloseButton: false,
        ),
        backgroundColor: Colors.transparent,
        // Set background color to transparent
        duration: Duration(seconds: Utils.appConstants.snackbarDuration),
        snackPosition: SnackPosition.BOTTOM,
        padding: EdgeInsets.zero,
        // Remove padding
        margin: const EdgeInsets.only(bottom: 5.0),
        // Add bottom margin for spacing
        borderRadius: 0,
        // Remove border radius
        overlayBlur: 0,
        // Remove overlay blur if any
        overlayColor: Colors.transparent,
        // Set overlay color to transparent
        isDismissible: true,
        // Allow dismissing the snackbar
        snackStyle: SnackStyle.FLOATING,
        // Ensure it's floating
        forwardAnimationCurve: Curves.easeOut,
        reverseAnimationCurve: Curves.easeIn, snackbarStatus: (status) {
      if (status == SnackbarStatus.CLOSED) {
        if (onDismiss != null) {
          onDismiss();
        }
      }
    });
  });
}