| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:nomo/config/theme/theme_extensions/theme_extension.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: Get.reactiveTheme.cardColor, // 先让背景透明
- 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),
- messageText: Text(
- message,
- style: TextStyle(color: Get.reactiveTheme.textTheme.bodyLarge!.color),
- ),
- );
- }
- 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: Get.reactiveTheme.cardColor, // 先让背景透明
- 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),
- messageText: Text(
- message,
- style: TextStyle(color: Get.reactiveTheme.textTheme.bodyLarge!.color),
- ),
- );
- }
- 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,
- );
- }
- }
|