show static method
- BuildContext context,
- String message
Shows an error message using a custom positioned SnackBar
Implementation
static void show(BuildContext context, String message) {
// Ensure any existing snackbars are removed
ScaffoldMessenger.of(context).hideCurrentSnackBar();
// Calculate position at 25% from top
final screenHeight = MediaQuery.of(context).size.height;
final topPadding = MediaQuery.of(context).padding.top;
final availableHeight = screenHeight - topPadding;
// Position at 25% from top of available height, adding the status bar padding
final snackbarTopPosition = (availableHeight * 0.25) + topPadding;
// Create a snack bar with fixed top position
final snackBar = SnackBar(
content: Text(message),
behavior: SnackBarBehavior.floating,
backgroundColor: Colors.red,
margin: EdgeInsets.only(
bottom: screenHeight - snackbarTopPosition - 40, // 40 is approximate snackbar height
right: 10,
left: 10,
),
);
debugPrint('[DEBUG] Showing error message at ${snackbarTopPosition}px from top: $message');
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}