showWarningSnackBar static method
Displays an awesome-styled warning snackbar with optional dismiss callback.
Shows a visually rich warning 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 warning message to display (required, skips if empty)title: Custom title (defaults to "Warning" if empty)onDismiss: Optional callback function triggered when snackbar closes
The snackbar features:
- Orange background color (warning 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.showWarningSnackBar(
'Please verify your email',
title: 'Account Warning',
onDismiss: () => print('Warning dismissed'),
);
See also:
- showSuccessfulSnackBar for success messages
- showFailureSnackBar for error messages
Implementation
static void showWarningSnackBar(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.warning),
inMaterialBanner: false,
title: title.toString().isEmpty
? ContentType.warning.message.toString().capitalizeFirst!
: title,
message: message,
messageFontSize: Utils.appFontFamily.textSmallestSize,
contentType: ContentType.warning,
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();
}
}
});
});
}