fix: 修复复制地址提示层级问题,改用 toast 提示
- 创建统一的 ToastUtils 工具类 - 使用 BotToast.showCustomText 确保显示在所有弹窗之上 - 更新三处复制地址的代码使用新的 toast 方案 - 添加阴影效果提升视觉层次 - 支持成功/错误/警告等多种提示类型
This commit is contained in:
95
flutter_monisuo/lib/core/utils/toast_utils.dart
Normal file
95
flutter_monisuo/lib/core/utils/toast_utils.dart
Normal file
@@ -0,0 +1,95 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
|
||||
/// Toast 工具类 - 提供统一的 toast 提示功能
|
||||
///
|
||||
/// 使用 bot_toast 实现,确保 toast 显示在所有弹窗之上
|
||||
class ToastUtils {
|
||||
ToastUtils._();
|
||||
|
||||
/// 显示普通提示
|
||||
static void show(String message, {Duration? duration}) {
|
||||
BotToast.showCustomText(
|
||||
toastBuilder: (_) => _buildToastWidget(message),
|
||||
align: Alignment.center,
|
||||
duration: duration ?? const Duration(seconds: 2),
|
||||
onlyOne: true,
|
||||
crossPage: true,
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示成功提示
|
||||
static void showSuccess(String message, {Duration? duration}) {
|
||||
BotToast.showCustomText(
|
||||
toastBuilder: (_) => _buildToastWidget(
|
||||
message,
|
||||
backgroundColor: Colors.green.shade700,
|
||||
),
|
||||
align: Alignment.center,
|
||||
duration: duration ?? const Duration(seconds: 2),
|
||||
onlyOne: true,
|
||||
crossPage: true,
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示错误提示
|
||||
static void showError(String message, {Duration? duration}) {
|
||||
BotToast.showCustomText(
|
||||
toastBuilder: (_) => _buildToastWidget(
|
||||
message,
|
||||
backgroundColor: Colors.red.shade700,
|
||||
),
|
||||
align: Alignment.center,
|
||||
duration: duration ?? const Duration(seconds: 3),
|
||||
onlyOne: true,
|
||||
crossPage: true,
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示警告提示
|
||||
static void showWarning(String message, {Duration? duration}) {
|
||||
BotToast.showCustomText(
|
||||
toastBuilder: (_) => _buildToastWidget(
|
||||
message,
|
||||
backgroundColor: Colors.orange.shade700,
|
||||
),
|
||||
align: Alignment.center,
|
||||
duration: duration ?? const Duration(seconds: 2),
|
||||
onlyOne: true,
|
||||
crossPage: true,
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建 toast widget
|
||||
static Widget _buildToastWidget(
|
||||
String message, {
|
||||
Color? backgroundColor,
|
||||
}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor ?? Colors.black87,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
message,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user