feat: 充值/提现页面改为独立全屏页面,优化Toast提示

This commit is contained in:
2026-04-07 04:24:39 +08:00
parent 7fc4dc71cb
commit 020a2bf352
92 changed files with 61289 additions and 59813 deletions

View File

@@ -1,95 +1,154 @@
import 'package:flutter/material.dart';
import 'package:bot_toast/bot_toast.dart';
/// Toast 工具類 - 提供統一的 toast 提示功能
///
/// 使用 bot_toast 實現,確保 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,
);
_showToast(message, _ToastType.info, duration: duration);
}
/// 顯示成功提示
/// 顯示成功提示(綠色圖標)
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,
);
_showToast(message, _ToastType.success, duration: duration);
}
/// 顯示錯誤提示
/// 顯示錯誤提示(紅色圖標)
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,
);
_showToast(message, _ToastType.error, duration: duration ?? const Duration(seconds: 3));
}
/// 顯示警告提示
/// 顯示警告提示(橙色圖標)
static void showWarning(String message, {Duration? duration}) {
_showToast(message, _ToastType.warning, duration: duration);
}
static void _showToast(
String message,
_ToastType type, {
Duration? duration,
}) {
BotToast.showCustomText(
toastBuilder: (_) => _buildToastWidget(
message,
backgroundColor: Colors.orange.shade700,
),
toastBuilder: (_) => _ToastWidget(message: message, type: type),
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,
),
);
}
}
/// Toast 類型
enum _ToastType {
success,
error,
warning,
info,
}
/// Toast Widget - 支付寶/微信風格
class _ToastWidget extends StatelessWidget {
final String message;
final _ToastType type;
const _ToastWidget({required this.message, required this.type});
@override
Widget build(BuildContext context) {
final config = _typeConfig;
final isDark = Theme.of(context).brightness == Brightness.dark;
return Container(
constraints: const BoxConstraints(maxWidth: 280),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
decoration: BoxDecoration(
color: isDark ? const Color(0xE6292D36) : const Color(0xE6FFFFFF),
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: isDark ? 0.3 : 0.15),
blurRadius: 16,
offset: const Offset(0, 4),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 圖標
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: config.backgroundColor,
shape: BoxShape.circle,
),
child: Icon(
config.icon,
color: config.iconColor,
size: 20,
),
),
const SizedBox(height: 10),
// 文字
Text(
message,
style: TextStyle(
color: isDark ? const Color(0xFFF8FAFC) : const Color(0xFF1F2937),
fontSize: 14,
fontWeight: FontWeight.w500,
height: 1.4,
),
textAlign: TextAlign.center,
),
],
),
);
}
_ToastConfig get _typeConfig {
switch (type) {
case _ToastType.success:
return _ToastConfig(
icon: Icons.check_circle_outline_rounded,
iconColor: const Color(0xFFFFFFFF),
backgroundColor: const Color(0xFF16A34A),
);
case _ToastType.error:
return _ToastConfig(
icon: Icons.cancel_outlined,
iconColor: const Color(0xFFFFFFFF),
backgroundColor: const Color(0xFFDC2626),
);
case _ToastType.warning:
return _ToastConfig(
icon: Icons.error_outline_rounded,
iconColor: const Color(0xFFFFFFFF),
backgroundColor: const Color(0xFFF59E0B),
);
case _ToastType.info:
return _ToastConfig(
icon: Icons.info_outline_rounded,
iconColor: const Color(0xFFFFFFFF),
backgroundColor: const Color(0xFF3B82F6),
);
}
}
}
class _ToastConfig {
final IconData icon;
final Color iconColor;
final Color backgroundColor;
const _ToastConfig({
required this.icon,
required this.iconColor,
required this.backgroundColor,
});
}

View File

@@ -6,12 +6,13 @@ import '../../../core/theme/app_theme.dart';
import '../../../core/event/app_event_bus.dart';
import '../../../providers/asset_provider.dart';
import 'components/action_buttons_row.dart';
import 'components/asset_dialogs.dart';
import 'components/balance_card.dart';
import 'components/holdings_section.dart';
import 'components/records_link_row.dart';
import '../orders/fund_orders_page.dart';
import 'deposit_page.dart';
import 'transfer_page.dart';
import 'withdraw_page.dart';
/// 資產頁面 - Matching .pen design spec (CMcqs)
class AssetPage extends StatefulWidget {
@@ -104,8 +105,8 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
const SizedBox(height: AppSpacing.md),
// Action buttons row — matching .pen pIpHe (gap 12)
ActionButtonsRow(
onDeposit: () => showDepositDialog(context),
onWithdraw: () => showWithdrawDialog(context, provider.fundAccount?.balance),
onDeposit: () => _navigateToDeposit(context),
onWithdraw: () => _navigateToWithdraw(context, provider.fundAccount?.balance),
onTransfer: () => _navigateToTransfer(context),
),
const SizedBox(height: AppSpacing.md),
@@ -145,4 +146,24 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
context.read<AssetProvider>().refreshAll(force: true);
}
}
void _navigateToDeposit(BuildContext context) async {
final result = await Navigator.push<bool>(
context,
MaterialPageRoute(builder: (_) => const DepositPage()),
);
if (result == true && context.mounted) {
context.read<AssetProvider>().refreshAll(force: true);
}
}
void _navigateToWithdraw(BuildContext context, String? balance) async {
final result = await Navigator.push<bool>(
context,
MaterialPageRoute(builder: (_) => WithdrawPage(balance: balance)),
);
if (result == true && context.mounted) {
context.read<AssetProvider>().refreshAll(force: true);
}
}
}

View File

@@ -94,7 +94,7 @@ class WalletAddressCard extends StatelessWidget {
GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(text: address));
ToastUtils.show('地址已複製到剪貼板');
ToastUtils.showSuccess('地址已複製到剪貼板');
},
child: Container(
padding: const EdgeInsets.all(AppSpacing.xs),

View File

@@ -0,0 +1,616 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:provider/provider.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import '../../../core/theme/app_color_scheme.dart';
import '../../../core/theme/app_spacing.dart';
import '../../../core/theme/app_theme.dart';
import '../../../core/theme/app_theme_extension.dart';
import '../../../core/utils/toast_utils.dart';
import '../../../providers/asset_provider.dart';
/// 充值頁面 — 獨立頁面,替代彈窗
class DepositPage extends StatefulWidget {
const DepositPage({super.key});
@override
State<DepositPage> createState() => _DepositPageState();
}
class _DepositPageState extends State<DepositPage> {
final _amountController = TextEditingController();
final _formKey = GlobalKey<ShadFormState>();
bool _isSubmitting = false;
// 充值結果狀態
bool _showResult = false;
String? _orderNo;
String? _amount;
String? _walletAddress;
String _walletNetwork = 'TRC20';
@override
void dispose() {
_amountController.dispose();
super.dispose();
}
Future<void> _submitDeposit() async {
if (!_formKey.currentState!.saveAndValidate()) return;
if (_isSubmitting) return;
setState(() => _isSubmitting = true);
try {
final response = await context.read<AssetProvider>().deposit(
amount: _amountController.text,
);
if (!mounted) return;
if (response.success && response.data != null) {
setState(() {
_showResult = true;
_orderNo = response.data!['orderNo'] as String? ?? '';
_amount = response.data!['amount']?.toString() ?? '0.00';
_walletAddress = response.data!['walletAddress'] as String? ?? '';
_walletNetwork = response.data!['walletNetwork'] as String? ?? 'TRC20';
});
} else {
ToastUtils.showError(response.message ?? '申請失敗');
}
} catch (e) {
if (mounted) ToastUtils.showError('申請失敗: $e');
} finally {
if (mounted) setState(() => _isSubmitting = false);
}
}
Future<void> _confirmPay() async {
if (_orderNo == null) return;
final confirmed = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('確認已打款'),
content: const Text('確認您已完成向指定地址的轉賬?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: const Text('取消'),
),
TextButton(
onPressed: () => Navigator.pop(ctx, true),
child: const Text('確認'),
),
],
),
);
if (confirmed != true || !mounted) return;
try {
final response = await context.read<AssetProvider>().confirmPay(_orderNo!);
if (!mounted) return;
if (response.success) {
ToastUtils.showSuccess('確認成功,請等待管理員審核');
Navigator.of(context).pop(true);
} else {
ToastUtils.showError(response.message ?? '確認失敗');
}
} catch (e) {
if (mounted) ToastUtils.showError('確認失敗: $e');
}
}
// ============================================
// 構建 UI
// ============================================
@override
Widget build(BuildContext context) {
final colorScheme = context.colors;
return Scaffold(
backgroundColor: colorScheme.background,
appBar: AppBar(
leading: IconButton(
icon: const Icon(LucideIcons.arrowLeft, size: 20),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
'充值',
style: AppTextStyles.headlineLarge(context).copyWith(
color: colorScheme.onSurface,
),
),
backgroundColor: colorScheme.background,
elevation: 0,
scrolledUnderElevation: 0,
centerTitle: true,
),
body: _showResult ? _buildResultView() : _buildFormView(),
);
}
/// 表單視圖 — 輸入充值金額
Widget _buildFormView() {
final colorScheme = context.colors;
return SingleChildScrollView(
padding: const EdgeInsets.all(AppSpacing.lg),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 幣種選擇卡片
Container(
width: double.infinity,
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(AppRadius.lg),
border: Border.all(
color: colorScheme.outlineVariant.withValues(alpha: 0.3),
),
),
child: Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: colorScheme.primary.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(AppRadius.md),
),
child: Icon(
LucideIcons.coins,
color: colorScheme.primary,
size: 20,
),
),
const SizedBox(width: AppSpacing.md),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'USDT',
style: AppTextStyles.headlineMedium(context).copyWith(
fontWeight: FontWeight.bold,
),
),
Text(
'Tether USD',
style: AppTextStyles.bodySmall(context).copyWith(
color: colorScheme.onSurfaceVariant,
),
),
],
),
),
],
),
),
const SizedBox(height: AppSpacing.xl),
// 金額輸入
Text(
'充值金額',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: AppSpacing.sm),
ShadForm(
key: _formKey,
child: ShadInputFormField(
id: 'amount',
controller: _amountController,
placeholder: const Text('請輸入充值金額'),
keyboardType: const TextInputType.numberWithOptions(decimal: true),
validator: (v) {
if (v == null || v.isEmpty) return '請輸入金額';
final n = double.tryParse(v);
if (n == null || n <= 0) return '請輸入有效金額';
if (n < 1000) return '單筆最低充值 1000 USDT';
return null;
},
),
),
const SizedBox(height: AppSpacing.sm),
// 最低金額提示
Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.md,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
color: AppColorScheme.info.withValues(alpha: 0.08),
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(
color: AppColorScheme.info.withValues(alpha: 0.15),
),
),
child: Row(
children: [
Icon(Icons.info_outline, size: 16, color: AppColorScheme.info),
const SizedBox(width: AppSpacing.sm),
Text(
'單筆最低充值 1000 USDT',
style: AppTextStyles.bodySmall(context).copyWith(
color: AppColorScheme.info,
),
),
],
),
),
const SizedBox(height: AppSpacing.xl),
// 操作說明
Text(
'操作流程',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: AppSpacing.md),
_buildStepItem(1, '輸入充值金額並提交申請'),
_buildStepItem(2, '向指定錢包地址轉賬'),
_buildStepItem(3, '點擊「已打款」確認'),
_buildStepItem(4, '等待管理員審核通過'),
const SizedBox(height: AppSpacing.xxl),
// 提交按鈕
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: _isSubmitting ? null : _submitDeposit,
style: ElevatedButton.styleFrom(
backgroundColor: colorScheme.primary,
foregroundColor: colorScheme.onPrimary,
disabledBackgroundColor: colorScheme.primary.withValues(alpha: 0.5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.lg),
),
elevation: 0,
),
child: _isSubmitting
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
: Text(
'下一步',
style: AppTextStyles.headlineMedium(context).copyWith(
fontWeight: FontWeight.w600,
color: colorScheme.onPrimary,
),
),
),
),
const SizedBox(height: AppSpacing.lg),
// 安全提示
_buildSecurityTip(),
],
),
);
}
/// 結果視圖 — 展示錢包地址和確認打款
Widget _buildResultView() {
final colorScheme = context.colors;
return SingleChildScrollView(
padding: const EdgeInsets.all(AppSpacing.lg),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 成功提示
Center(
child: Column(
children: [
Container(
width: 56,
height: 56,
decoration: BoxDecoration(
color: context.appColors.up.withValues(alpha: 0.12),
shape: BoxShape.circle,
),
child: Icon(
Icons.check_circle_outline_rounded,
color: context.appColors.up,
size: 32,
),
),
const SizedBox(height: AppSpacing.md),
Text(
'充值申請成功',
style: AppTextStyles.headlineLarge(context).copyWith(
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: AppSpacing.xs),
Text(
'請向以下地址轉賬完成充值',
style: AppTextStyles.bodyMedium(context).copyWith(
color: colorScheme.onSurfaceVariant,
),
),
],
),
),
const SizedBox(height: AppSpacing.xl),
// 訂單信息
Container(
width: double.infinity,
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(AppRadius.lg),
border: Border.all(
color: colorScheme.outlineVariant.withValues(alpha: 0.3),
),
),
child: Column(
children: [
_buildInfoRow('訂單號', _orderNo ?? ''),
const SizedBox(height: AppSpacing.sm),
Divider(color: colorScheme.outlineVariant.withValues(alpha: 0.2), height: 1),
const SizedBox(height: AppSpacing.sm),
_buildInfoRow('充值金額', '${_amount ?? "0.00"} USDT', isBold: true),
],
),
),
const SizedBox(height: AppSpacing.lg),
// 錢包地址
Text(
'收款地址',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: AppSpacing.sm),
Container(
width: double.infinity,
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(AppRadius.lg),
border: Border.all(
color: colorScheme.outlineVariant.withValues(alpha: 0.3),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
_walletAddress ?? '',
style: AppTextStyles.bodyMedium(context).copyWith(
fontFamily: 'monospace',
),
),
),
GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(text: _walletAddress ?? ''));
ToastUtils.showSuccess('地址已複製到剪貼板');
},
child: Container(
padding: const EdgeInsets.all(AppSpacing.sm),
decoration: BoxDecoration(
color: colorScheme.primary.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(AppRadius.sm),
),
child: Icon(
LucideIcons.copy,
size: 16,
color: colorScheme.primary,
),
),
),
],
),
const SizedBox(height: AppSpacing.sm),
Text(
'網絡: $_walletNetwork',
style: AppTextStyles.bodySmall(context).copyWith(
color: colorScheme.onSurfaceVariant,
),
),
],
),
),
const SizedBox(height: AppSpacing.md),
// 重要提示
Container(
width: double.infinity,
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColorScheme.warning.withValues(alpha: 0.08),
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(
color: AppColorScheme.warning.withValues(alpha: 0.15),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.info_outline, size: 18, color: AppColorScheme.warning),
const SizedBox(width: AppSpacing.sm),
Expanded(
child: Text(
'轉賬完成後請點擊下方「已打款」按鈕確認,管理員審核通過後資金將到賬。',
style: AppTextStyles.bodyMedium(context).copyWith(
color: AppColorScheme.warning,
),
),
),
],
),
),
const SizedBox(height: AppSpacing.xl),
// 操作按鈕
Row(
children: [
Expanded(
child: SizedBox(
height: 50,
child: OutlinedButton(
onPressed: () => Navigator.of(context).pop(),
style: OutlinedButton.styleFrom(
side: BorderSide(color: colorScheme.outline),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.lg),
),
),
child: Text(
'稍後確認',
style: AppTextStyles.headlineSmall(context).copyWith(
fontWeight: FontWeight.w600,
),
),
),
),
),
const SizedBox(width: AppSpacing.md),
Expanded(
child: SizedBox(
height: 50,
child: ElevatedButton(
onPressed: _confirmPay,
style: ElevatedButton.styleFrom(
backgroundColor: colorScheme.primary,
foregroundColor: colorScheme.onPrimary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.lg),
),
elevation: 0,
),
child: Text(
'已打款',
style: AppTextStyles.headlineSmall(context).copyWith(
fontWeight: FontWeight.w600,
color: colorScheme.onPrimary,
),
),
),
),
),
],
),
const SizedBox(height: AppSpacing.lg),
_buildSecurityTip(),
],
),
);
}
// ============================================
// 輔助組件
// ============================================
Widget _buildStepItem(int step, String text) {
final colorScheme = context.colors;
return Padding(
padding: const EdgeInsets.only(bottom: AppSpacing.sm + AppSpacing.xs),
child: Row(
children: [
Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: colorScheme.primary.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(AppRadius.sm),
),
child: Center(
child: Text(
'$step',
style: AppTextStyles.labelSmall(context).copyWith(
color: colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(width: AppSpacing.sm),
Expanded(
child: Text(
text,
style: AppTextStyles.bodyMedium(context).copyWith(
color: colorScheme.onSurfaceVariant,
),
),
),
],
),
);
}
Widget _buildInfoRow(String label, String value, {bool isBold = false}) {
final colorScheme = context.colors;
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
label,
style: AppTextStyles.bodyMedium(context).copyWith(
color: colorScheme.onSurfaceVariant,
),
),
Flexible(
child: Text(
value,
style: AppTextStyles.bodyMedium(context).copyWith(
fontWeight: isBold ? FontWeight.bold : FontWeight.w400,
),
textAlign: TextAlign.right,
),
),
],
);
}
Widget _buildSecurityTip() {
final colorScheme = context.colors;
return Container(
width: double.infinity,
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(AppRadius.md),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.verified_user_outlined,
size: 14,
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.5),
),
const SizedBox(width: AppSpacing.xs),
Text(
'資金安全由平台全程保障',
style: AppTextStyles.bodySmall(context).copyWith(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.5),
),
),
],
),
);
}
}

View File

@@ -0,0 +1,409 @@
import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:provider/provider.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import '../../../core/theme/app_color_scheme.dart';
import '../../../core/theme/app_spacing.dart';
import '../../../core/theme/app_theme.dart';
import '../../../core/theme/app_theme_extension.dart';
import '../../../core/utils/toast_utils.dart';
import '../../../providers/asset_provider.dart';
import '../../shared/ui_constants.dart';
/// 提現頁面 — 獨立頁面,替代彈窗
class WithdrawPage extends StatefulWidget {
final String? balance;
const WithdrawPage({super.key, this.balance});
@override
State<WithdrawPage> createState() => _WithdrawPageState();
}
class _WithdrawPageState extends State<WithdrawPage> {
final _amountController = TextEditingController();
final _addressController = TextEditingController();
final _contactController = TextEditingController();
final _formKey = GlobalKey<ShadFormState>();
bool _isSubmitting = false;
final _feeNotifier = ValueNotifier<String>('提現將扣除 10% 手續費');
final _networksNotifier = ValueNotifier<List<String>>([]);
final _selectedNetworkNotifier = ValueNotifier<String?>(null);
@override
void initState() {
super.initState();
_amountController.addListener(_onAmountChanged);
_loadNetworks();
}
@override
void dispose() {
_amountController.dispose();
_addressController.dispose();
_contactController.dispose();
_feeNotifier.dispose();
_networksNotifier.dispose();
_selectedNetworkNotifier.dispose();
super.dispose();
}
void _onAmountChanged() {
final amount = double.tryParse(_amountController.text) ?? 0;
if (amount > 0) {
final fee = amount * 0.1;
final receivable = amount - fee;
_feeNotifier.value =
'手續費(10%): -${fee.toStringAsFixed(2)} USDT\n應收款: ${receivable.toStringAsFixed(2)} USDT';
} else {
_feeNotifier.value = '提現將扣除 10% 手續費';
}
}
void _loadNetworks() {
context.read<AssetProvider>().getWalletNetworks().then((list) {
if (mounted) {
_networksNotifier.value = list;
if (list.isNotEmpty) {
_selectedNetworkNotifier.value = list.first;
}
}
});
}
Future<void> _submitWithdraw() async {
if (!_formKey.currentState!.saveAndValidate()) return;
if (_isSubmitting) return;
setState(() => _isSubmitting = true);
try {
final response = await context.read<AssetProvider>().withdraw(
amount: _amountController.text,
withdrawAddress: _addressController.text,
withdrawContact:
_contactController.text.isNotEmpty ? _contactController.text : null,
network: _selectedNetworkNotifier.value,
);
if (!mounted) return;
if (response.success) {
ToastUtils.showSuccess('申請成功,請等待管理員審批');
Navigator.of(context).pop(true);
} else {
ToastUtils.showError(response.message ?? '申請失敗');
}
} catch (e) {
if (mounted) ToastUtils.showError('申請失敗: $e');
} finally {
if (mounted) setState(() => _isSubmitting = false);
}
}
// ============================================
// 構建 UI
// ============================================
@override
Widget build(BuildContext context) {
final colorScheme = context.colors;
return Scaffold(
backgroundColor: colorScheme.background,
appBar: AppBar(
leading: IconButton(
icon: const Icon(LucideIcons.arrowLeft, size: 20),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
'提現',
style: AppTextStyles.headlineLarge(context).copyWith(
color: colorScheme.onSurface,
),
),
backgroundColor: colorScheme.background,
elevation: 0,
scrolledUnderElevation: 0,
centerTitle: true,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(AppSpacing.lg),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 餘額顯示
if (widget.balance != null) ...[
Container(
width: double.infinity,
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(AppRadius.lg),
border: Border.all(
color: colorScheme.outlineVariant.withValues(alpha: 0.3),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'可用餘額',
style: AppTextStyles.bodyMedium(context).copyWith(
color: colorScheme.onSurfaceVariant,
),
),
Text(
'${widget.balance} USDT',
style: AppTextStyles.headlineMedium(context).copyWith(
fontWeight: FontWeight.bold,
color: context.appColors.up,
),
),
],
),
),
const SizedBox(height: AppSpacing.lg),
],
// 表單
ShadForm(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 提現金額
Text(
'提現金額',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: AppSpacing.sm),
ShadInputFormField(
id: 'amount',
controller: _amountController,
placeholder: const Text('請輸入提現金額 (USDT)'),
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
validator: Validators.amount,
),
const SizedBox(height: AppSpacing.sm),
// 手續費提示
ValueListenableBuilder<String>(
valueListenable: _feeNotifier,
builder: (_, feeText, __) {
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.md,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
color: colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(AppRadius.md),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.info_outline,
size: 14, color: colorScheme.onSurfaceVariant),
const SizedBox(width: AppSpacing.xs),
Expanded(
child: Text(
feeText,
style: AppTextStyles.bodySmall(context).copyWith(
color: colorScheme.onSurfaceVariant,
),
),
),
],
),
);
},
),
const SizedBox(height: AppSpacing.lg),
// 提現網絡
ValueListenableBuilder<List<String>>(
valueListenable: _networksNotifier,
builder: (_, networks, __) {
if (networks.isEmpty) return const SizedBox.shrink();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'提現網絡',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: AppSpacing.sm),
ValueListenableBuilder<String?>(
valueListenable: _selectedNetworkNotifier,
builder: (_, selected, __) {
return SizedBox(
width: double.infinity,
child: ShadSelect<String>(
placeholder: const Text('選擇提現網絡'),
initialValue: selected,
selectedOptionBuilder: (context, val) =>
Text(val),
onChanged: (value) {
if (value != null) {
_selectedNetworkNotifier.value = value;
}
},
options: networks
.map((n) =>
ShadOption(value: n, child: Text(n)))
.toList(),
),
);
},
),
const SizedBox(height: AppSpacing.lg),
],
);
},
),
// 目標地址
Text(
'目標地址',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: AppSpacing.sm),
ShadInputFormField(
id: 'address',
controller: _addressController,
placeholder: const Text('請輸入提現地址'),
validator: (v) => Validators.required(v, '提現地址'),
),
const SizedBox(height: AppSpacing.lg),
// 聯繫方式
Text(
'聯繫方式(可選)',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: AppSpacing.sm),
ShadInputFormField(
id: 'contact',
controller: _contactController,
placeholder: const Text('方便客服與您聯繫'),
),
],
),
),
const SizedBox(height: AppSpacing.xl),
// 安全提示
Container(
width: double.infinity,
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColorScheme.warning.withValues(alpha: 0.08),
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(
color: AppColorScheme.warning.withValues(alpha: 0.15),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.shield_outlined,
size: 16, color: AppColorScheme.warning),
const SizedBox(width: AppSpacing.xs),
Text(
'安全提示',
style: AppTextStyles.labelLarge(context).copyWith(
fontWeight: FontWeight.w600,
color: AppColorScheme.warning,
),
),
],
),
const SizedBox(height: AppSpacing.sm),
Text(
'• 請仔細核對提現地址,地址錯誤將導致資產無法找回\n'
'• 提現申請提交後需等待管理員審批\n'
'• 提現將扣除 10% 手續費',
style: AppTextStyles.bodySmall(context).copyWith(
color: colorScheme.onSurfaceVariant,
height: 1.6,
),
),
],
),
),
const SizedBox(height: AppSpacing.xl),
// 提交按鈕
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: _isSubmitting ? null : _submitWithdraw,
style: ElevatedButton.styleFrom(
backgroundColor: colorScheme.primary,
foregroundColor: colorScheme.onPrimary,
disabledBackgroundColor:
colorScheme.primary.withValues(alpha: 0.5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.lg),
),
elevation: 0,
),
child: _isSubmitting
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
: Text(
'提交申請',
style: AppTextStyles.headlineMedium(context).copyWith(
fontWeight: FontWeight.w600,
color: colorScheme.onPrimary,
),
),
),
),
const SizedBox(height: AppSpacing.lg),
// 底部安全保障
Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.verified_user_outlined,
size: 14,
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.5),
),
const SizedBox(width: AppSpacing.xs),
Text(
'資金安全由平台全程保障',
style: AppTextStyles.bodySmall(context).copyWith(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.5),
),
),
],
),
),
],
),
),
);
}
}

View File

@@ -13,7 +13,8 @@ import '../../../providers/asset_provider.dart';
import '../../components/glass_panel.dart';
import '../mine/welfare_center_page.dart';
import '../asset/transfer_page.dart';
import '../asset/components/asset_dialogs.dart';
import '../asset/deposit_page.dart';
import '../asset/withdraw_page.dart';
import '../../components/coin_icon.dart';
import 'header_bar.dart';
import 'quick_actions_row.dart';
@@ -145,12 +146,18 @@ class _HomePageState extends State<HomePage>
}
void _showDeposit() {
showDepositDialog(context);
Navigator.push(
context,
MaterialPageRoute(builder: (_) => const DepositPage()),
);
}
void _showWithdraw() {
final balance = context.read<AssetProvider>().fundAccount?.balance ?? '0.00';
showWithdrawDialog(context, balance);
Navigator.push(
context,
MaterialPageRoute(builder: (_) => WithdrawPage(balance: balance)),
);
}
void _navigateToTransfer() {

View File

@@ -238,7 +238,7 @@ class _WelfareCenterPageState extends State<WelfareCenterPage> {
? null
: () {
Clipboard.setData(ClipboardData(text: referralCode));
ToastUtils.show('邀請碼已複製');
ToastUtils.showSuccess('邀請碼已複製');
},
style: ElevatedButton.styleFrom(
backgroundColor: goldAccent,
@@ -860,13 +860,13 @@ class _WelfareCenterPageState extends State<WelfareCenterPage> {
if (response.success) {
context.read<AssetProvider>().refreshAll(force: true);
context.read<AppEventBus>().fire(AppEventType.assetChanged);
ToastUtils.show('領取成功100 USDT 已到賬');
ToastUtils.showSuccess('領取成功100 USDT 已到賬');
_loadData();
} else {
ToastUtils.show(response.message ?? '領取失敗');
ToastUtils.showError(response.message ?? '領取失敗');
}
} catch (e) {
ToastUtils.show('領取失敗: $e');
ToastUtils.showError('領取失敗: $e');
}
}
@@ -882,13 +882,13 @@ class _WelfareCenterPageState extends State<WelfareCenterPage> {
if (response.success) {
context.read<AssetProvider>().refreshAll(force: true);
context.read<AppEventBus>().fire(AppEventType.assetChanged);
ToastUtils.show('領取成功100 USDT 已到賬');
ToastUtils.showSuccess('領取成功100 USDT 已到賬');
_loadData();
} else {
ToastUtils.show(response.message ?? '領取失敗');
ToastUtils.showError(response.message ?? '領取失敗');
}
} catch (e) {
ToastUtils.show('領取失敗: $e');
ToastUtils.showError('領取失敗: $e');
}
}
@@ -909,13 +909,13 @@ class _WelfareCenterPageState extends State<WelfareCenterPage> {
if (response.success) {
context.read<AssetProvider>().refreshAll(force: true);
context.read<AppEventBus>().fire(AppEventType.assetChanged);
ToastUtils.show('領取成功50 USDT 已到賬');
ToastUtils.showSuccess('領取成功50 USDT 已到賬');
_loadData();
} else {
ToastUtils.show(response.message ?? '領取失敗');
ToastUtils.showError(response.message ?? '領取失敗');
}
} catch (e) {
ToastUtils.show('領取失敗: $e');
ToastUtils.showError('領取失敗: $e');
}
}
}

View File

@@ -2,7 +2,6 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:provider/provider.dart';
import '../../../core/theme/app_color_scheme.dart';
import '../../../core/theme/app_spacing.dart';
@@ -333,7 +332,7 @@ class _FundOrdersPageState extends State<FundOrdersPage> {
trailing: GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(text: order.walletAddress!));
ToastUtils.show('地址已複製');
ToastUtils.showSuccess('地址已複製');
},
child: Icon(LucideIcons.copy, size: 14, color: context.appColors.onSurfaceMuted),
),
@@ -474,7 +473,11 @@ class _FundOrdersPageState extends State<FundOrdersPage> {
if (confirmed == true && mounted) {
final response = await context.read<AssetProvider>().confirmPay(order.orderNo);
if (mounted) {
BotToast.showText(text: response.success ? '確認成功,請等待審核' : response.message ?? '確認失敗');
if (response.success) {
ToastUtils.showSuccess('確認成功,請等待審核');
} else {
ToastUtils.showError(response.message ?? '確認失敗');
}
}
}
}
@@ -490,7 +493,11 @@ class _FundOrdersPageState extends State<FundOrdersPage> {
if (confirmed == true && mounted) {
final response = await context.read<AssetProvider>().cancelOrder(order.orderNo);
if (mounted) {
BotToast.showText(text: response.success ? '訂單已取消' : response.message ?? '取消失敗');
if (response.success) {
ToastUtils.showSuccess('訂單已取消');
} else {
ToastUtils.showError(response.message ?? '取消失敗');
}
}
}
}