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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:provider/single_child_widget.dart';
|
||||
@@ -117,7 +118,14 @@ class MyApp extends StatelessWidget {
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
builder: (context, child) => ShadAppBuilder(child: child!),
|
||||
builder: (context, child) {
|
||||
child = ShadAppBuilder(child: child!);
|
||||
// 配置 BotToast 确保显示在所有内容之上
|
||||
final botToastBuilder = BotToastInit();
|
||||
child = botToastBuilder(context, child);
|
||||
return child;
|
||||
},
|
||||
navigatorObservers: [BotToastNavigatorObserver()],
|
||||
initialRoute: '/',
|
||||
routes: {
|
||||
'/': (context) => const RootPage(),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../../../core/theme/app_color_scheme.dart';
|
||||
import '../../../core/theme/app_spacing.dart';
|
||||
import '../../../core/utils/toast_utils.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
import '../../../providers/auth_provider.dart';
|
||||
import '../../shared/ui_constants.dart';
|
||||
@@ -862,9 +864,7 @@ class _WalletAddressCard extends StatelessWidget {
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: address));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('地址已复制到剪贴板')),
|
||||
);
|
||||
ToastUtils.show('地址已复制到剪贴板');
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(AppSpacing.xs),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../../../core/theme/app_color_scheme.dart';
|
||||
import '../../../core/theme/app_spacing.dart';
|
||||
import '../../../core/utils/toast_utils.dart';
|
||||
import '../../../data/models/account_models.dart';
|
||||
import '../../../data/services/asset_service.dart';
|
||||
import '../../../data/services/bonus_service.dart';
|
||||
@@ -1346,9 +1348,7 @@ class _WalletAddressCard extends StatelessWidget {
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: address));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('地址已复制到剪贴板')),
|
||||
);
|
||||
ToastUtils.show('地址已复制到剪贴板');
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(AppSpacing.xs),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/utils/toast_utils.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
import '../../../data/models/order_models.dart';
|
||||
|
||||
@@ -245,9 +247,7 @@ class _FundOrdersPageState extends State<FundOrdersPage> {
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: order.walletAddress!));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('地址已复制')),
|
||||
);
|
||||
ToastUtils.show('地址已复制');
|
||||
},
|
||||
child: Icon(LucideIcons.copy, size: 14, color: Colors.grey[600]),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user