showSuccess static method

void showSuccess(
  1. BuildContext context,
  2. String message
)

Shows a success message using a custom positioned SnackBar

Implementation

static void showSuccess(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.green,
    margin: EdgeInsets.only(
      bottom: screenHeight - snackbarTopPosition - 40, // 40 is approximate snackbar height
      right: 10,
      left: 10,
    ),
  );

  debugPrint('[DEBUG] Showing success message at ${snackbarTopPosition}px from top: $message');
  ScaffoldMessenger.of(context).showSnackBar(snackBar);
}