showSnackBar method

void showSnackBar({
  1. required String message,
  2. Color backgroundColor = Colors.white,
})

Implementation

void showSnackBar({
  required String message,
  Color backgroundColor = Colors.white,
}) {
  // Use a post-frame callback to ensure the context is valid
  WidgetsBinding.instance.addPostFrameCallback((_) {
    // Verify the context is still mounted and valid
    if (!mounted) return;

    try {
      ScaffoldMessenger.of(this).showSnackBar(SnackBar(
        content: Text(message),
        backgroundColor: backgroundColor,
      ));
    } catch (e) {
      // If ScaffoldMessenger is not available, silently fail
      debugPrint('Warning: Could not show snackbar - $e');
    }
  });
}