showSimpleWarningSnackBar method
void
showSimpleWarningSnackBar(})
Displays a simple warning snackbar at the bottom of the screen.
Shows a basic GetX snackbar with customizable title, message, and background color. Automatically unfocuses any active text fields before displaying. If the message is empty or whitespace-only, no snackbar is shown.
Parameters:
message: The message text to display (required)title: The title text to display (required)backgroundColor: Background color of the snackbar (defaults to white)
The snackbar appears at the bottom, displays for 3 seconds, and has:
- White text color
- 16px border radius
- 16px margin on all sides
Example:
RtCommonFunction.instance.showSimpleWarningSnackBar(
'Please check your input',
'Warning',
backgroundColor: Colors.orange,
);
Implementation
void showSimpleWarningSnackBar(String message, String title,
{Color? backgroundColor = Colors.white}) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (message.trim().isEmpty) {
return;
}
Get.focusScope?.unfocus();
Get.snackbar(
title, message, snackPosition: SnackPosition.BOTTOM,
// Position of the SnackBar
duration: const Duration(seconds: 3),
// Duration for how long the SnackBar should be displayed
backgroundColor: backgroundColor,
// Background color of the SnackBar
colorText: Colors.white,
// Text color of the SnackBar
borderRadius: 16,
// Border radius for curved corners
margin: const EdgeInsets.all(16), // Margin around the SnackBar
);
});
}