Some checks failed
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Windows / build (push) Has been cancelled
127 lines
3.3 KiB
Dart
127 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
class KRSnackBarUtil {
|
|
// 全局默认样式配置
|
|
static const Color _defaultBackgroundColor = Colors.black;
|
|
static const double _defaultBorderRadius = 8.0;
|
|
static const EdgeInsets _defaultMargin = EdgeInsets.all(16);
|
|
static const Duration _defaultDuration = Duration(seconds: 3);
|
|
static const SnackPosition _defaultPosition = SnackPosition.TOP;
|
|
|
|
static Color _getBgColor() {
|
|
// 默认使用主题的主色
|
|
return Get.theme.primaryColor;
|
|
}
|
|
|
|
/// 显示基础消息(使用全局默认样式)
|
|
static void show(String title, String message) {
|
|
Get.snackbar(
|
|
title,
|
|
message,
|
|
backgroundColor: _defaultBackgroundColor,
|
|
colorText: _getBgColor(),
|
|
borderRadius: _defaultBorderRadius,
|
|
margin: _defaultMargin,
|
|
duration: _defaultDuration,
|
|
snackPosition: _defaultPosition,
|
|
);
|
|
}
|
|
|
|
/// 显示成功消息
|
|
static void showSuccess(String title, String message) {
|
|
Get.snackbar(
|
|
title,
|
|
message,
|
|
backgroundColor: _defaultBackgroundColor,
|
|
colorText: _getBgColor(),
|
|
borderRadius: _defaultBorderRadius,
|
|
margin: _defaultMargin,
|
|
duration: _defaultDuration,
|
|
snackPosition: _defaultPosition,
|
|
icon: const Icon(
|
|
Icons.check_circle,
|
|
color: Colors.green,
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 显示错误消息
|
|
static void showError(String title, String message) {
|
|
Get.snackbar(
|
|
title,
|
|
message,
|
|
backgroundColor: _defaultBackgroundColor,
|
|
colorText: _getBgColor(),
|
|
borderRadius: _defaultBorderRadius,
|
|
margin: _defaultMargin,
|
|
duration: _defaultDuration,
|
|
snackPosition: _defaultPosition,
|
|
icon: const Icon(
|
|
Icons.error,
|
|
color: Colors.red,
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 显示警告消息
|
|
static void showWarning(String title, String message) {
|
|
Get.snackbar(
|
|
title,
|
|
message,
|
|
backgroundColor: _defaultBackgroundColor,
|
|
colorText: _getBgColor(),
|
|
borderRadius: _defaultBorderRadius,
|
|
margin: _defaultMargin,
|
|
duration: _defaultDuration,
|
|
snackPosition: _defaultPosition,
|
|
icon: const Icon(
|
|
Icons.warning,
|
|
color: Colors.orange,
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 显示信息消息
|
|
static void showInfo(String title, String message) {
|
|
Get.snackbar(
|
|
title,
|
|
message,
|
|
backgroundColor: _defaultBackgroundColor,
|
|
colorText: _getBgColor(),
|
|
borderRadius: _defaultBorderRadius,
|
|
margin: _defaultMargin,
|
|
duration: _defaultDuration,
|
|
snackPosition: _defaultPosition,
|
|
icon: const Icon(
|
|
Icons.info,
|
|
color: Colors.blue,
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 显示自定义样式的消息
|
|
static void showCustom({
|
|
required String title,
|
|
required String message,
|
|
Color? backgroundColor,
|
|
Color? textColor,
|
|
Widget? icon,
|
|
Duration? duration,
|
|
SnackPosition? position,
|
|
double? borderRadius,
|
|
EdgeInsets? margin,
|
|
}) {
|
|
Get.snackbar(
|
|
title,
|
|
message,
|
|
backgroundColor: backgroundColor ?? _defaultBackgroundColor,
|
|
colorText: textColor ?? _getBgColor(),
|
|
borderRadius: borderRadius ?? _defaultBorderRadius,
|
|
margin: margin ?? _defaultMargin,
|
|
duration: duration ?? _defaultDuration,
|
|
snackPosition: position ?? _defaultPosition,
|
|
icon: icon,
|
|
);
|
|
}
|
|
} |