111
This commit is contained in:
@@ -8,7 +8,7 @@ import '../../../core/theme/app_spacing.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
import '../../../data/models/account_models.dart';
|
||||
|
||||
/// 划转页面
|
||||
/// 劃轉頁面
|
||||
class TransferPage extends StatefulWidget {
|
||||
const TransferPage({super.key});
|
||||
|
||||
@@ -19,7 +19,7 @@ class TransferPage extends StatefulWidget {
|
||||
class _TransferPageState extends State<TransferPage> {
|
||||
final _amountController = TextEditingController();
|
||||
final _focusNode = FocusNode();
|
||||
int _direction = 1; // 1: 资金→交易, 2: 交易→资金
|
||||
int _direction = 1; // 1: 資金→交易, 2: 交易→資金
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
@@ -38,26 +38,26 @@ class _TransferPageState extends State<TransferPage> {
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 数据访问
|
||||
// 數據訪問
|
||||
// ============================================
|
||||
|
||||
/// 获取资金账户余额(安全检查)
|
||||
/// 獲取資金賬戶餘額(安全檢查)
|
||||
String get _fundBalance {
|
||||
try {
|
||||
final provider = context.read<AssetProvider>();
|
||||
final balance = provider.fundAccount?.balance ?? provider.overview?.fundBalance ?? '0.00';
|
||||
// 确保返回的是有效的数字格式
|
||||
// 確保返回的是有效的數字格式
|
||||
return _formatBalance(balance);
|
||||
} catch (e) {
|
||||
return '0.00';
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取交易账户 USDT 余额(安全检查)
|
||||
/// 獲取交易賬戶 USDT 餘額(安全檢查)
|
||||
String get _tradeUsdtBalance {
|
||||
try {
|
||||
final provider = context.read<AssetProvider>();
|
||||
// 先检查列表是否为空
|
||||
// 先檢查列表是否為空
|
||||
if (provider.tradeAccounts.isEmpty) {
|
||||
return '0.00';
|
||||
}
|
||||
@@ -81,32 +81,32 @@ class _TransferPageState extends State<TransferPage> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取当前可用余额(根据方向)
|
||||
/// 獲取當前可用餘額(根據方向)
|
||||
String get _availableBalance => _direction == 1 ? _fundBalance : _tradeUsdtBalance;
|
||||
|
||||
/// 从账户名
|
||||
String get _fromLabel => _direction == 1 ? '资金账户' : '交易账户';
|
||||
String get _toLabel => _direction == 1 ? '交易账户' : '资金账户';
|
||||
/// 從賬戶名
|
||||
String get _fromLabel => _direction == 1 ? '資金賬戶' : '交易賬戶';
|
||||
String get _toLabel => _direction == 1 ? '交易賬戶' : '資金賬戶';
|
||||
String get _fromBalance => _direction == 1 ? _fundBalance : _tradeUsdtBalance;
|
||||
String get _toBalance => _direction == 1 ? _tradeUsdtBalance : _fundBalance;
|
||||
|
||||
// ============================================
|
||||
// 业务逻辑
|
||||
// 業務邏輯
|
||||
// ============================================
|
||||
|
||||
/// 执行划转
|
||||
/// 執行劃轉
|
||||
Future<void> _doTransfer() async {
|
||||
final amount = _amountController.text;
|
||||
final available = double.tryParse(_availableBalance) ?? 0;
|
||||
final transferAmount = double.tryParse(amount) ?? 0;
|
||||
|
||||
if (transferAmount <= 0) {
|
||||
_showSnackBar('请输入有效的划转金额');
|
||||
_showSnackBar('請輸入有效的劃轉金額');
|
||||
return;
|
||||
}
|
||||
|
||||
if (transferAmount > available) {
|
||||
_showSnackBar('余额不足');
|
||||
_showSnackBar('餘額不足');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -121,10 +121,10 @@ class _TransferPageState extends State<TransferPage> {
|
||||
if (mounted) {
|
||||
if (response.success) {
|
||||
_amountController.clear();
|
||||
_showSnackBar('划转成功');
|
||||
_showSnackBar('劃轉成功');
|
||||
Navigator.of(context).pop(true);
|
||||
} else {
|
||||
_showSnackBar(response.message ?? '划转失败');
|
||||
_showSnackBar(response.message ?? '劃轉失敗');
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -140,14 +140,14 @@ class _TransferPageState extends State<TransferPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 设置快捷百分比金额
|
||||
/// 設置快捷百分比金額
|
||||
void _setQuickAmount(double percent) {
|
||||
final available = double.tryParse(_availableBalance) ?? 0;
|
||||
final amount = available * percent;
|
||||
_amountController.text = amount.toStringAsFixed(8).replaceAll(RegExp(r'\.?0+$'), '');
|
||||
}
|
||||
|
||||
/// 切换方向
|
||||
/// 切換方向
|
||||
void _toggleDirection() {
|
||||
setState(() {
|
||||
_direction = _direction == 1 ? 2 : 1;
|
||||
@@ -155,7 +155,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 构建 UI
|
||||
// 構建 UI
|
||||
// ============================================
|
||||
|
||||
@override
|
||||
@@ -173,7 +173,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
title: Text(
|
||||
'账户划转',
|
||||
'賬戶劃轉',
|
||||
style: AppTextStyles.headlineLarge(context),
|
||||
),
|
||||
centerTitle: true,
|
||||
@@ -205,7 +205,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
|
||||
Widget _buildTransferDirectionCard() {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
// 金色主题感知: Dark #D4AF37 (primary), Light #F59E0B (secondary)
|
||||
// 金色主題感知: Dark #D4AF37 (primary), Light #F59E0B (secondary)
|
||||
final goldAccent = colorScheme.brightness == Brightness.dark
|
||||
? colorScheme.primary
|
||||
: colorScheme.secondary;
|
||||
@@ -225,7 +225,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
key: 'src-$_direction',
|
||||
beginOffset: const Offset(0, -1),
|
||||
child: _buildAccountRow(
|
||||
label: '从',
|
||||
label: '從',
|
||||
accountName: _fromLabel,
|
||||
balance: _fromBalance,
|
||||
),
|
||||
@@ -239,7 +239,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
height: 40,
|
||||
margin: const EdgeInsets.symmetric(vertical: AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
// 椭圆形半透明金色背景
|
||||
// 橢圓形半透明金色背景
|
||||
color: goldAccent.withValues(alpha: 0.15),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
@@ -272,7 +272,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 统一的 AnimatedSwitcher 构造
|
||||
/// 統一的 AnimatedSwitcher 構造
|
||||
Widget _animatedSwitcher({
|
||||
required String key,
|
||||
required Offset beginOffset,
|
||||
@@ -313,7 +313,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
label == '从' ? LucideIcons.wallet : LucideIcons.trendingUp,
|
||||
label == '從' ? LucideIcons.wallet : LucideIcons.trendingUp,
|
||||
size: 18,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
@@ -342,14 +342,14 @@ class _TransferPageState extends State<TransferPage> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Label row: "划转金额" + "全部划转"
|
||||
// Label row: "劃轉金額" + "全部劃轉"
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('划转金额', style: AppTextStyles.headlineSmall(context).copyWith(color: colorScheme.onSurfaceVariant)),
|
||||
Text('劃轉金額', style: AppTextStyles.headlineSmall(context).copyWith(color: colorScheme.onSurfaceVariant)),
|
||||
GestureDetector(
|
||||
onTap: () => _setQuickAmount(1.0),
|
||||
child: Text('全部划转', style: AppTextStyles.labelLarge(context).copyWith(
|
||||
child: Text('全部劃轉', style: AppTextStyles.labelLarge(context).copyWith(
|
||||
color: colorScheme.secondary,
|
||||
fontWeight: FontWeight.w600,
|
||||
)),
|
||||
@@ -461,7 +461,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'划转即时到账,无需手续费',
|
||||
'劃轉即時到賬,無需手續費',
|
||||
style: AppTextStyles.bodyMedium(context).copyWith(color: upColor),
|
||||
),
|
||||
),
|
||||
@@ -472,7 +472,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
|
||||
Widget _buildConfirmButton() {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
// 金色主题感知: Dark #D4AF37 (primary), Light #F59E0B (secondary)
|
||||
// 金色主題感知: Dark #D4AF37 (primary), Light #F59E0B (secondary)
|
||||
final goldAccent = colorScheme.brightness == Brightness.dark
|
||||
? colorScheme.primary
|
||||
: colorScheme.secondary;
|
||||
@@ -498,7 +498,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'确认划转',
|
||||
'確認劃轉',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
|
||||
Reference in New Issue
Block a user