import 'package:flutter/material.dart'; class CustomSnackBar { static void showSuccess({ required BuildContext context, required String message, Duration duration = const Duration(seconds: 3), }) { _showCustomSnackBar( context: context, message: message, backgroundColor: const Color(0xFF4CAF50), // Green icon: Icons.check_circle, duration: duration, ); } static void showError({ required BuildContext context, required String message, Duration duration = const Duration(seconds: 4), }) { _showCustomSnackBar( context: context, message: message, backgroundColor: const Color(0xFFF44336), // Red icon: Icons.error, duration: duration, ); } static void showInfo({ required BuildContext context, required String message, Duration duration = const Duration(seconds: 3), }) { _showCustomSnackBar( context: context, message: message, backgroundColor: const Color(0xFF2196F3), // Blue icon: Icons.info, duration: duration, ); } static void showWarning({ required BuildContext context, required String message, Duration duration = const Duration(seconds: 4), }) { _showCustomSnackBar( context: context, message: message, backgroundColor: const Color(0xFFFF9800), // Orange icon: Icons.warning, duration: duration, ); } static void showLoading({ required BuildContext context, required String message, Duration duration = const Duration(seconds: 5), }) { _showCustomSnackBar( context: context, message: message, backgroundColor: const Color(0xFF2d2d2d), // Dark gray icon: Icons.hourglass_empty, isLoading: true, duration: duration, ); } static void _showCustomSnackBar({ required BuildContext context, required String message, required Color backgroundColor, required IconData icon, bool isLoading = false, Duration duration = const Duration(seconds: 3), }) { ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( SnackBar( backgroundColor: backgroundColor, duration: duration, elevation: 6, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), behavior: SnackBarBehavior.floating, margin: const EdgeInsets.all(16), content: Row( children: [ if (isLoading) SizedBox( width: 20, height: 20, child: CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation(Colors.white), ), ) else Icon( icon, color: Colors.white, size: 20, ), const SizedBox(width: 12), Expanded( child: Text( message, style: const TextStyle( fontFamily: "Plus Jakarta Sans", fontWeight: FontWeight.w500, fontSize: 14, color: Colors.white, ), ), ), ], ), ), ); } static void hide(BuildContext context) { ScaffoldMessenger.of(context).hideCurrentSnackBar(); } }