import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../constants/assets.dart'; class IXSnackBar { static String? _lastMessage; static DateTime? _lastShowTime; static bool _shouldShowSnackbar(String message) { final now = DateTime.now(); if (message == _lastMessage && _lastShowTime != null && now.difference(_lastShowTime!).inSeconds < 3) { return false; } _lastMessage = message; _lastShowTime = now; return true; } static showIXSnackBar( {required String title, required String message, Duration? duration}) { if (!_shouldShowSnackbar(message)) return; // Get.snackbar( // title, // message, // duration: duration ?? const Duration(seconds: 3), // margin: const EdgeInsets.only(top: 10, left: 10, right: 10), // colorText: Palette.white, // backgroundColor: Palette.snackbarBgColor, // borderColor: Palette.snackbarBorderColor, // borderWidth: 1, // borderRadius: 16, // icon: Image.asset( // Assets.pwdSuccess, // width: 20, // height: 20, // ), // ); Get.rawSnackbar( message: message, backgroundColor: Colors.transparent, // 先让背景透明 snackStyle: SnackStyle.floating, // 悬浮样式 duration: duration ?? const Duration(seconds: 3), margin: const EdgeInsets.only(top: 10, left: 10, right: 10), snackPosition: SnackPosition.top, // backgroundColor: Palette.snackbarBgColor, barBlur: 7.0, // borderColor: , borderWidth: 1, borderRadius: 16, icon: Image.asset( Assets.success, width: 20, height: 20, ), ); } static showIXErrorSnackBar( {required String title, required String message, Color? color, Duration? duration}) { if (!_shouldShowSnackbar(message)) return; // Get.snackbar( // title, // message, // duration: duration ?? const Duration(seconds: 3), // margin: const EdgeInsets.only(top: 10, left: 10, right: 10), // colorText: Palette.white, // backgroundColor: color ?? Palette.snackbarBgColor, // borderColor: Palette.snackbarBorderColor, // borderWidth: 1.w, // borderRadius: 16.r, // icon: Image.asset( // Assets.pwdError, // width: 20.w, // height: 20.w, // ), // ); Get.rawSnackbar( message: message, backgroundColor: Colors.transparent, // 先让背景透明 snackStyle: SnackStyle.floating, // 悬浮样式 duration: duration ?? const Duration(seconds: 3), margin: const EdgeInsets.only(top: 10, left: 10, right: 10), snackPosition: SnackPosition.top, // backgroundColor: Palette.snackbarBgColor, barBlur: 7.0, // borderColor: Palette.snackbarBorderColor, borderWidth: 1, borderRadius: 16, icon: Image.asset( Assets.error, width: 20, height: 20, ), ); } static showIXToast( {String? title, required String message, Color? color, Duration? duration}) { if (!_shouldShowSnackbar(message)) return; Get.rawSnackbar( title: title, duration: duration ?? const Duration(seconds: 3), snackStyle: SnackStyle.grounded, backgroundColor: color ?? Colors.green, onTap: (snack) { Get.closeAllSnackbars(); }, //overlayBlur: 0.8, message: message, ); } static showIXErrorToast( {String? title, required String message, Color? color, Duration? duration}) { if (!_shouldShowSnackbar(message)) return; Get.rawSnackbar( title: title, duration: duration ?? const Duration(seconds: 3), snackStyle: SnackStyle.grounded, backgroundColor: color ?? Colors.redAccent, onTap: (snack) { Get.closeAllSnackbars(); }, //overlayBlur: 0.8, message: message, ); } }