2026-03-27 20:40:51 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
|
import 'package:provider/provider.dart';
|
2026-04-05 22:24:04 +08:00
|
|
|
|
import 'package:lucide_icons_flutter/lucide_icons.dart';
|
2026-04-05 23:37:27 +08:00
|
|
|
|
import '../../../core/theme/app_theme.dart';
|
2026-03-27 20:40:51 +08:00
|
|
|
|
import '../../../core/theme/app_spacing.dart';
|
|
|
|
|
|
import '../../../providers/asset_provider.dart';
|
|
|
|
|
|
import '../../../data/models/account_models.dart';
|
2026-04-08 11:44:10 +08:00
|
|
|
|
import '../../components/material_input.dart';
|
2026-03-27 20:40:51 +08:00
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
/// 划转页面
|
2026-03-27 20:40:51 +08:00
|
|
|
|
class TransferPage extends StatefulWidget {
|
|
|
|
|
|
const TransferPage({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<TransferPage> createState() => _TransferPageState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
class _TransferPageState extends State<TransferPage> {
|
2026-03-27 20:40:51 +08:00
|
|
|
|
final _amountController = TextEditingController();
|
2026-04-05 22:24:04 +08:00
|
|
|
|
final _focusNode = FocusNode();
|
2026-04-08 01:47:51 +08:00
|
|
|
|
int _direction = 1; // 1: 资金→交易, 2: 交易→资金
|
2026-03-27 20:40:51 +08:00
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
2026-04-08 01:47:51 +08:00
|
|
|
|
_amountController.addListener(() => setState(() {}));
|
2026-03-27 20:40:51 +08:00
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
|
context.read<AssetProvider>().refreshAll(force: true);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void dispose() {
|
|
|
|
|
|
_amountController.dispose();
|
2026-04-05 22:24:04 +08:00
|
|
|
|
_focusNode.dispose();
|
2026-03-27 20:40:51 +08:00
|
|
|
|
super.dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 数据访问
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
|
|
|
|
|
|
2026-03-27 20:40:51 +08:00
|
|
|
|
String get _fundBalance {
|
2026-04-06 03:57:00 +08:00
|
|
|
|
try {
|
|
|
|
|
|
final provider = context.read<AssetProvider>();
|
2026-04-08 01:47:51 +08:00
|
|
|
|
final balance = provider.fundAccount?.balance ??
|
|
|
|
|
|
provider.overview?.fundBalance ??
|
|
|
|
|
|
'0.00';
|
2026-04-06 03:57:00 +08:00
|
|
|
|
return _formatBalance(balance);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
return '0.00';
|
|
|
|
|
|
}
|
2026-03-27 20:40:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String get _tradeUsdtBalance {
|
2026-04-06 03:57:00 +08:00
|
|
|
|
try {
|
|
|
|
|
|
final provider = context.read<AssetProvider>();
|
2026-04-08 01:47:51 +08:00
|
|
|
|
if (provider.tradeAccounts.isEmpty) return '0.00';
|
2026-04-06 03:57:00 +08:00
|
|
|
|
final usdtHolding = provider.tradeAccounts.firstWhere(
|
|
|
|
|
|
(t) => t.coinCode.toUpperCase() == 'USDT',
|
|
|
|
|
|
orElse: () => AccountTrade(
|
|
|
|
|
|
id: 0,
|
|
|
|
|
|
userId: 0,
|
|
|
|
|
|
coinCode: 'USDT',
|
|
|
|
|
|
quantity: '0',
|
|
|
|
|
|
avgPrice: '1',
|
|
|
|
|
|
totalCost: '0',
|
|
|
|
|
|
currentValue: '0',
|
|
|
|
|
|
profit: '0',
|
|
|
|
|
|
profitRate: 0,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
return _formatBalance(usdtHolding.quantity);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
return '0.00';
|
|
|
|
|
|
}
|
2026-03-27 20:40:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
String get _availableBalance =>
|
|
|
|
|
|
_direction == 1 ? _fundBalance : _tradeUsdtBalance;
|
2026-03-27 20:40:51 +08:00
|
|
|
|
|
2026-04-08 01:58:53 +08:00
|
|
|
|
String get _fromLabel => _direction == 1 ? '資金賬戶' : '交易賬戶';
|
|
|
|
|
|
String get _toLabel => _direction == 1 ? '交易賬戶' : '資金賬戶';
|
2026-03-30 03:49:31 +08:00
|
|
|
|
String get _fromBalance => _direction == 1 ? _fundBalance : _tradeUsdtBalance;
|
|
|
|
|
|
String get _toBalance => _direction == 1 ? _tradeUsdtBalance : _fundBalance;
|
|
|
|
|
|
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 业务逻辑
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
|
|
|
|
|
|
2026-03-27 20:40:51 +08:00
|
|
|
|
Future<void> _doTransfer() async {
|
|
|
|
|
|
final amount = _amountController.text;
|
|
|
|
|
|
final available = double.tryParse(_availableBalance) ?? 0;
|
|
|
|
|
|
final transferAmount = double.tryParse(amount) ?? 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (transferAmount <= 0) {
|
2026-04-08 01:58:53 +08:00
|
|
|
|
_showSnackBar('請輸入有效的劃轉金額');
|
2026-03-27 20:40:51 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (transferAmount > available) {
|
2026-04-08 01:58:53 +08:00
|
|
|
|
_showSnackBar('餘額不足');
|
2026-03-27 20:40:51 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setState(() => _isLoading = true);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
final response = await context.read<AssetProvider>().transfer(
|
2026-04-08 01:47:51 +08:00
|
|
|
|
direction: _direction,
|
|
|
|
|
|
amount: amount,
|
|
|
|
|
|
);
|
2026-03-27 20:40:51 +08:00
|
|
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
|
|
if (response.success) {
|
|
|
|
|
|
_amountController.clear();
|
2026-04-08 01:58:53 +08:00
|
|
|
|
_showSnackBar('劃轉成功');
|
2026-04-07 03:19:19 +08:00
|
|
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
2026-04-08 01:47:51 +08:00
|
|
|
|
if (mounted) Navigator.of(context).pop(true);
|
2026-03-27 20:40:51 +08:00
|
|
|
|
} else {
|
2026-04-08 01:58:53 +08:00
|
|
|
|
_showSnackBar(response.message ?? '劃轉失敗');
|
2026-03-27 20:40:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
2026-04-08 01:47:51 +08:00
|
|
|
|
if (mounted) setState(() => _isLoading = false);
|
2026-03-27 20:40:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _showSnackBar(String message) {
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2026-04-07 03:19:19 +08:00
|
|
|
|
SnackBar(
|
|
|
|
|
|
content: Text(message),
|
|
|
|
|
|
behavior: SnackBarBehavior.floating,
|
|
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
|
|
|
|
),
|
2026-03-27 20:40:51 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-30 03:49:31 +08:00
|
|
|
|
void _setQuickAmount(double percent) {
|
|
|
|
|
|
final available = double.tryParse(_availableBalance) ?? 0;
|
|
|
|
|
|
final amount = available * percent;
|
2026-04-08 01:09:57 +08:00
|
|
|
|
// 向下截斷到2位小數,避免四捨五入超出餘額
|
|
|
|
|
|
_amountController.text =
|
|
|
|
|
|
((amount * 100).truncateToDouble() / 100).toStringAsFixed(2);
|
|
|
|
|
|
|
2026-04-07 03:19:19 +08:00
|
|
|
|
// Trigger haptic feedback
|
|
|
|
|
|
HapticFeedback.selectionClick();
|
2026-03-30 03:49:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
void _toggleDirection() {
|
2026-04-07 03:19:19 +08:00
|
|
|
|
HapticFeedback.mediumImpact();
|
2026-04-08 01:47:51 +08:00
|
|
|
|
setState(() => _direction = _direction == 1 ? 2 : 1);
|
2026-03-30 11:41:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 构建 UI
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
|
|
|
|
|
|
2026-03-27 20:40:51 +08:00
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-04-05 23:37:27 +08:00
|
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
2026-04-05 22:24:04 +08:00
|
|
|
|
|
2026-03-27 20:40:51 +08:00
|
|
|
|
return Scaffold(
|
2026-04-05 23:37:27 +08:00
|
|
|
|
backgroundColor: colorScheme.surface,
|
2026-03-27 20:40:51 +08:00
|
|
|
|
appBar: AppBar(
|
2026-04-07 03:19:19 +08:00
|
|
|
|
backgroundColor: Colors.transparent,
|
2026-03-27 20:40:51 +08:00
|
|
|
|
elevation: 0,
|
2026-04-05 22:24:04 +08:00
|
|
|
|
scrolledUnderElevation: 0,
|
2026-03-27 20:40:51 +08:00
|
|
|
|
leading: IconButton(
|
2026-04-08 01:47:51 +08:00
|
|
|
|
icon: Icon(LucideIcons.arrowLeft,
|
|
|
|
|
|
color: colorScheme.onSurface, size: 20),
|
2026-03-27 20:40:51 +08:00
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
|
),
|
|
|
|
|
|
title: Text(
|
2026-04-08 01:58:53 +08:00
|
|
|
|
'賬戶劃轉',
|
2026-04-07 03:19:19 +08:00
|
|
|
|
style: AppTextStyles.headlineLarge(context).copyWith(
|
2026-04-08 01:47:51 +08:00
|
|
|
|
fontWeight: FontWeight.w600,
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
2026-03-27 20:40:51 +08:00
|
|
|
|
),
|
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
|
),
|
|
|
|
|
|
body: Consumer<AssetProvider>(
|
|
|
|
|
|
builder: (context, provider, _) {
|
2026-04-08 01:47:51 +08:00
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(
|
|
|
|
|
|
AppSpacing.md, AppSpacing.xs, AppSpacing.md, AppSpacing.xl),
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
_buildTransferCard(colorScheme),
|
|
|
|
|
|
const SizedBox(height: AppSpacing.md),
|
|
|
|
|
|
_buildAmountSection(colorScheme),
|
|
|
|
|
|
const SizedBox(height: AppSpacing.md),
|
|
|
|
|
|
_buildTips(colorScheme),
|
|
|
|
|
|
const SizedBox(height: AppSpacing.xl),
|
|
|
|
|
|
_buildConfirmButton(colorScheme),
|
|
|
|
|
|
const SizedBox(height: AppSpacing.lg),
|
|
|
|
|
|
],
|
2026-03-27 20:40:51 +08:00
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 划转方向卡片
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
|
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Widget _buildTransferCard(ColorScheme colorScheme) {
|
2026-03-27 20:40:51 +08:00
|
|
|
|
return Container(
|
2026-03-30 03:49:31 +08:00
|
|
|
|
width: double.infinity,
|
2026-03-27 20:40:51 +08:00
|
|
|
|
decoration: BoxDecoration(
|
2026-04-08 01:47:51 +08:00
|
|
|
|
color: colorScheme.surface,
|
|
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
border: Border.all(
|
2026-04-08 01:47:51 +08:00
|
|
|
|
color: colorScheme.outlineVariant.withValues(alpha: 0.5),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
width: 1,
|
|
|
|
|
|
),
|
2026-03-27 20:40:51 +08:00
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
child: Stack(
|
|
|
|
|
|
clipBehavior: Clip.none,
|
2026-03-27 20:40:51 +08:00
|
|
|
|
children: [
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Column(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
// From
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding:
|
|
|
|
|
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Text(
|
|
|
|
|
|
'从',
|
|
|
|
|
|
style: AppTextStyles.bodySmall(context).copyWith(
|
|
|
|
|
|
color: colorScheme.onSurfaceVariant,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
|
Text(
|
|
|
|
|
|
_fromLabel,
|
|
|
|
|
|
style:
|
|
|
|
|
|
AppTextStyles.bodyLarge(context).copyWith(
|
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Text(
|
|
|
|
|
|
_fromBalance,
|
|
|
|
|
|
style: AppTextStyles.bodyLarge(context).copyWith(
|
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
|
),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
|
|
|
|
|
],
|
2026-04-06 03:57:00 +08:00
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
),
|
|
|
|
|
|
Divider(
|
|
|
|
|
|
height: 1,
|
|
|
|
|
|
thickness: 1,
|
|
|
|
|
|
color: colorScheme.outlineVariant.withValues(alpha: 0.5),
|
|
|
|
|
|
),
|
|
|
|
|
|
// To
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding:
|
|
|
|
|
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Text(
|
|
|
|
|
|
'到',
|
|
|
|
|
|
style: AppTextStyles.bodySmall(context).copyWith(
|
|
|
|
|
|
color: colorScheme.onSurfaceVariant,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
|
Text(
|
|
|
|
|
|
_toLabel,
|
|
|
|
|
|
style:
|
|
|
|
|
|
AppTextStyles.bodyLarge(context).copyWith(
|
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Text(
|
|
|
|
|
|
_toBalance,
|
|
|
|
|
|
style: AppTextStyles.bodyLarge(context).copyWith(
|
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
|
),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2026-04-08 02:42:59 +08:00
|
|
|
|
// 交换按钮 - 右側居中分割線
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Positioned(
|
|
|
|
|
|
right: 12,
|
|
|
|
|
|
top: 20,
|
2026-04-08 02:42:59 +08:00
|
|
|
|
bottom: 20,
|
|
|
|
|
|
child: Center(
|
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
|
onTap: _toggleDirection,
|
|
|
|
|
|
child: Container(
|
|
|
|
|
|
width: 28,
|
|
|
|
|
|
height: 28,
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: colorScheme.surface,
|
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
|
border: Border.all(
|
|
|
|
|
|
color: colorScheme.outlineVariant,
|
|
|
|
|
|
width: 1,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Icon(
|
|
|
|
|
|
LucideIcons.repeat2,
|
|
|
|
|
|
size: 13,
|
|
|
|
|
|
color: colorScheme.onSurfaceVariant,
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
),
|
2026-03-30 03:49:31 +08:00
|
|
|
|
),
|
2026-04-05 22:24:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 金额输入区域
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
2026-04-05 22:24:04 +08:00
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Widget _buildAmountSection(ColorScheme colorScheme) {
|
2026-04-05 22:24:04 +08:00
|
|
|
|
return Column(
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
|
children: [
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 标题行
|
2026-04-05 22:24:04 +08:00
|
|
|
|
Row(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
|
children: [
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Text(
|
2026-04-08 01:58:53 +08:00
|
|
|
|
'劃轉金額',
|
2026-04-08 01:47:51 +08:00
|
|
|
|
style: AppTextStyles.bodyMedium(context).copyWith(
|
|
|
|
|
|
color: colorScheme.onSurfaceVariant,
|
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
|
),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
GestureDetector(
|
|
|
|
|
|
onTap: () => _setQuickAmount(1.0),
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
'全部',
|
|
|
|
|
|
style: AppTextStyles.bodyMedium(context).copyWith(
|
|
|
|
|
|
color: colorScheme.secondary,
|
|
|
|
|
|
fontWeight: FontWeight.w500,
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-04-05 22:24:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
const SizedBox(height: 12),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 金额输入框
|
2026-04-08 11:44:10 +08:00
|
|
|
|
MaterialInput(
|
|
|
|
|
|
controller: _amountController,
|
|
|
|
|
|
focusNode: _focusNode,
|
|
|
|
|
|
hintText: '0.00',
|
|
|
|
|
|
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
|
|
|
|
|
inputFormatters: [
|
|
|
|
|
|
FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,8}')),
|
|
|
|
|
|
],
|
|
|
|
|
|
onChanged: (_) => setState(() {}),
|
|
|
|
|
|
suffixIcon: Padding(
|
|
|
|
|
|
padding: const EdgeInsets.only(right: AppSpacing.md),
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
'USDT',
|
|
|
|
|
|
style: AppTextStyles.bodyMedium(context).copyWith(
|
|
|
|
|
|
color: colorScheme.onSurfaceVariant,
|
|
|
|
|
|
fontWeight: FontWeight.w500,
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
2026-04-08 11:44:10 +08:00
|
|
|
|
),
|
2026-04-05 22:24:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
const SizedBox(height: 10),
|
2026-04-05 22:24:04 +08:00
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 可用余额
|
2026-04-05 22:24:04 +08:00
|
|
|
|
Row(
|
2026-04-08 01:47:51 +08:00
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2026-04-07 03:19:19 +08:00
|
|
|
|
children: [
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Text(
|
2026-04-08 01:58:53 +08:00
|
|
|
|
'可用餘額',
|
2026-04-08 01:47:51 +08:00
|
|
|
|
style: AppTextStyles.bodySmall(context).copyWith(
|
|
|
|
|
|
color: colorScheme.onSurfaceVariant,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
Text(
|
|
|
|
|
|
'$_availableBalance USDT',
|
|
|
|
|
|
style: AppTextStyles.bodySmall(context).copyWith(
|
|
|
|
|
|
color: colorScheme.onSurfaceVariant,
|
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
|
|
|
|
|
|
|
// 百分比按钮
|
|
|
|
|
|
Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
_buildPercentButton('25%', 0.25, colorScheme),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
const SizedBox(width: 8),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
_buildPercentButton('50%', 0.50, colorScheme),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
const SizedBox(width: 8),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
_buildPercentButton('75%', 0.75, colorScheme),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
const SizedBox(width: 8),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
_buildPercentButton('100%', 1.0, colorScheme),
|
2026-04-07 03:19:19 +08:00
|
|
|
|
],
|
2026-04-05 22:24:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
],
|
2026-03-27 20:40:51 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Widget _buildPercentButton(
|
|
|
|
|
|
String label, double percent, ColorScheme colorScheme) {
|
2026-04-07 03:19:19 +08:00
|
|
|
|
return Expanded(
|
2026-04-08 01:47:51 +08:00
|
|
|
|
child: GestureDetector(
|
|
|
|
|
|
onTap: () => _setQuickAmount(percent),
|
|
|
|
|
|
child: Container(
|
|
|
|
|
|
height: 34,
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: colorScheme.surfaceContainerHighest.withValues(alpha: 0.5),
|
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Center(
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
label,
|
|
|
|
|
|
style: AppTextStyles.bodySmall(context).copyWith(
|
|
|
|
|
|
color: colorScheme.onSurfaceVariant,
|
|
|
|
|
|
fontWeight: FontWeight.w500,
|
2026-04-07 03:19:19 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-03-27 20:40:51 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 提示文字
|
2026-04-05 22:38:56 +08:00
|
|
|
|
// ============================================
|
|
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Widget _buildTips(ColorScheme colorScheme) {
|
|
|
|
|
|
return Padding(
|
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
2026-04-05 22:24:04 +08:00
|
|
|
|
child: Row(
|
2026-03-27 20:40:51 +08:00
|
|
|
|
children: [
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Icon(LucideIcons.info,
|
|
|
|
|
|
size: 13, color: colorScheme.onSurfaceVariant),
|
|
|
|
|
|
const SizedBox(width: 6),
|
|
|
|
|
|
Text(
|
2026-04-08 01:58:53 +08:00
|
|
|
|
'劃轉即時到賬,無需手續費',
|
2026-04-08 01:47:51 +08:00
|
|
|
|
style: AppTextStyles.bodySmall(context).copyWith(
|
|
|
|
|
|
color: colorScheme.onSurfaceVariant,
|
2026-03-27 20:40:51 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-07 03:19:19 +08:00
|
|
|
|
// ============================================
|
2026-04-08 01:47:51 +08:00
|
|
|
|
// 确认按钮
|
2026-04-07 03:19:19 +08:00
|
|
|
|
// ============================================
|
|
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
Widget _buildConfirmButton(ColorScheme colorScheme) {
|
|
|
|
|
|
final hasAmount = _amountController.text.isNotEmpty &&
|
|
|
|
|
|
double.tryParse(_amountController.text) != null &&
|
|
|
|
|
|
double.parse(_amountController.text) > 0;
|
2026-04-05 23:37:27 +08:00
|
|
|
|
|
2026-04-08 01:47:51 +08:00
|
|
|
|
return SizedBox(
|
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
|
height: 48,
|
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
|
onPressed: _isLoading ? null : _doTransfer,
|
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
|
backgroundColor: hasAmount
|
|
|
|
|
|
? colorScheme.onSurface
|
|
|
|
|
|
: colorScheme.surfaceContainerHighest,
|
|
|
|
|
|
foregroundColor: hasAmount
|
|
|
|
|
|
? colorScheme.surface
|
|
|
|
|
|
: colorScheme.onSurfaceVariant,
|
|
|
|
|
|
disabledBackgroundColor: colorScheme.surfaceContainerHighest,
|
|
|
|
|
|
disabledForegroundColor: colorScheme.onSurfaceVariant,
|
|
|
|
|
|
elevation: 0,
|
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
|
borderRadius: BorderRadius.circular(14),
|
2026-03-27 20:40:51 +08:00
|
|
|
|
),
|
2026-04-05 22:24:04 +08:00
|
|
|
|
),
|
2026-04-08 01:47:51 +08:00
|
|
|
|
child: _isLoading
|
|
|
|
|
|
? SizedBox(
|
|
|
|
|
|
width: 20,
|
|
|
|
|
|
height: 20,
|
|
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
|
|
strokeWidth: 2,
|
|
|
|
|
|
valueColor: AlwaysStoppedAnimation<Color>(
|
|
|
|
|
|
colorScheme.onSurfaceVariant,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
: Text(
|
2026-04-08 01:58:53 +08:00
|
|
|
|
'確認劃轉',
|
2026-04-08 01:47:51 +08:00
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-03-27 20:40:51 +08:00
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-04-05 22:38:56 +08:00
|
|
|
|
|
|
|
|
|
|
// ============================================
|
|
|
|
|
|
// Helpers
|
|
|
|
|
|
// ============================================
|
|
|
|
|
|
|
|
|
|
|
|
String _formatBalance(String balance) {
|
|
|
|
|
|
final val = double.tryParse(balance);
|
|
|
|
|
|
if (val == null) return '0.00';
|
|
|
|
|
|
return val.toStringAsFixed(2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|