变更内容: - 删除 uni-app x 项目 (app/ 目录) - 新增 Flutter 项目 (flutter_monisuo/ 目录) - 新增部署脚本 (deploy/ 目录) Flutter 项目功能: - 用户登录/注册 - 首页资产概览 - 行情币种列表 - 交易买卖操作 - 资产账户管理 - 充值/提现/划转 - 深色主题 - JWT Token 认证 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
456 lines
15 KiB
Dart
456 lines
15 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../../core/constants/app_colors.dart';
|
|
import '../../../providers/asset_provider.dart';
|
|
|
|
/// 资产页面
|
|
class AssetPage extends StatefulWidget {
|
|
const AssetPage({super.key});
|
|
|
|
@override
|
|
State<AssetPage> createState() => _AssetPageState();
|
|
}
|
|
|
|
class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixin {
|
|
@override
|
|
bool get wantKeepAlive => true;
|
|
|
|
int _activeTab = 0; // 0=资金账户, 1=交易账户
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
_loadData();
|
|
});
|
|
}
|
|
|
|
void _loadData() {
|
|
context.read<AssetProvider>().refreshAll();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
super.build(context);
|
|
return Scaffold(
|
|
backgroundColor: AppColors.background,
|
|
body: Consumer<AssetProvider>(
|
|
builder: (context, provider, _) {
|
|
return RefreshIndicator(
|
|
onRefresh: provider.refreshAll,
|
|
color: AppColors.primary,
|
|
child: SingleChildScrollView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
children: [
|
|
_buildAssetCard(provider),
|
|
const SizedBox(height: 16),
|
|
_buildAccountTabs(),
|
|
const SizedBox(height: 16),
|
|
_activeTab == 0
|
|
? _buildFundAccount(provider)
|
|
: _buildTradeAccount(provider),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildAssetCard(AssetProvider provider) {
|
|
final overview = provider.overview;
|
|
return Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(24),
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
colors: [AppColors.primary, AppColors.primaryDark],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
const Text(
|
|
'总资产估值(USDT)',
|
|
style: TextStyle(fontSize: 14, color: Colors.white70),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
overview?.totalAsset ?? '0.00',
|
|
style: const TextStyle(
|
|
fontSize: 36,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(Icons.trending_up, color: Colors.white70, size: 16),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
'总盈亏: ${overview?.totalProfit ?? '0.00'} USDT',
|
|
style: const TextStyle(fontSize: 14, color: Colors.white70),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildAccountTabs() {
|
|
return Container(
|
|
padding: const EdgeInsets.all(4),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardBackground,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: GestureDetector(
|
|
onTap: () => setState(() => _activeTab = 0),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
decoration: BoxDecoration(
|
|
color: _activeTab == 0 ? AppColors.primary : Colors.transparent,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
'资金账户',
|
|
style: TextStyle(
|
|
color: _activeTab == 0 ? Colors.white : AppColors.textSecondary,
|
|
fontWeight: _activeTab == 0 ? FontWeight.w600 : FontWeight.normal,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: GestureDetector(
|
|
onTap: () => setState(() => _activeTab = 1),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
decoration: BoxDecoration(
|
|
color: _activeTab == 1 ? AppColors.primary : Colors.transparent,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
'交易账户',
|
|
style: TextStyle(
|
|
color: _activeTab == 1 ? Colors.white : AppColors.textSecondary,
|
|
fontWeight: _activeTab == 1 ? FontWeight.w600 : FontWeight.normal,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildFundAccount(AssetProvider provider) {
|
|
final fund = provider.fundAccount;
|
|
return Column(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardBackground,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'USDT余额',
|
|
style: TextStyle(fontSize: 14, color: AppColors.textSecondary),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
fund?.balance ?? '0.00',
|
|
style: const TextStyle(
|
|
fontSize: 28,
|
|
fontWeight: FontWeight.bold,
|
|
color: AppColors.textPrimary,
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: ElevatedButton.icon(
|
|
onPressed: () => _showDepositDialog(provider),
|
|
icon: const Icon(Icons.add, size: 18),
|
|
label: const Text('充值'),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColors.success,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: ElevatedButton.icon(
|
|
onPressed: () => _showWithdrawDialog(provider),
|
|
icon: const Icon(Icons.remove, size: 18),
|
|
label: const Text('提现'),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColors.warning,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: ElevatedButton.icon(
|
|
onPressed: () => _showTransferDialog(provider),
|
|
icon: const Icon(Icons.swap_horiz, size: 18),
|
|
label: const Text('划转'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildTradeAccount(AssetProvider provider) {
|
|
final holdings = provider.holdings;
|
|
return Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardBackground,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'持仓列表',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
color: AppColors.textPrimary,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
if (holdings.isEmpty)
|
|
const Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(32),
|
|
child: Text(
|
|
'暂无持仓',
|
|
style: TextStyle(color: AppColors.textSecondary),
|
|
),
|
|
),
|
|
)
|
|
else
|
|
ListView.separated(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
itemCount: holdings.length,
|
|
separatorBuilder: (_, __) => const Divider(color: AppColors.border),
|
|
itemBuilder: (context, index) {
|
|
final holding = holdings[index];
|
|
return ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
leading: CircleAvatar(
|
|
backgroundColor: AppColors.primary.withOpacity(0.1),
|
|
child: Text(
|
|
holding.coinCode.substring(0, 1),
|
|
style: const TextStyle(color: AppColors.primary),
|
|
),
|
|
),
|
|
title: Text(
|
|
holding.coinCode,
|
|
style: const TextStyle(
|
|
color: AppColors.textPrimary,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
subtitle: Text(
|
|
'数量: ${holding.quantity}',
|
|
style: const TextStyle(color: AppColors.textSecondary, fontSize: 12),
|
|
),
|
|
trailing: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Text(
|
|
'${holding.currentValue} USDT',
|
|
style: const TextStyle(color: AppColors.textPrimary),
|
|
),
|
|
Text(
|
|
holding.formattedProfitRate,
|
|
style: TextStyle(
|
|
color: holding.isProfit ? AppColors.up : AppColors.down,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showDepositDialog(AssetProvider provider) {
|
|
final controller = TextEditingController();
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
backgroundColor: AppColors.cardBackground,
|
|
title: const Text('充值', style: TextStyle(color: AppColors.textPrimary)),
|
|
content: TextField(
|
|
controller: controller,
|
|
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
|
style: const TextStyle(color: AppColors.textPrimary),
|
|
decoration: const InputDecoration(
|
|
hintText: '请输入充值金额(USDT)',
|
|
hintStyle: TextStyle(color: AppColors.textHint),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('取消'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
Navigator.pop(context);
|
|
final response = await provider.deposit(amount: controller.text);
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(response.message ?? (response.success ? '申请成功' : '申请失败'))),
|
|
);
|
|
}
|
|
},
|
|
child: const Text('确认'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showWithdrawDialog(AssetProvider provider) {
|
|
final controller = TextEditingController();
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
backgroundColor: AppColors.cardBackground,
|
|
title: const Text('提现', style: TextStyle(color: AppColors.textPrimary)),
|
|
content: TextField(
|
|
controller: controller,
|
|
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
|
style: const TextStyle(color: AppColors.textPrimary),
|
|
decoration: const InputDecoration(
|
|
hintText: '请输入提现金额(USDT)',
|
|
hintStyle: TextStyle(color: AppColors.textHint),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('取消'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
Navigator.pop(context);
|
|
final response = await provider.withdraw(amount: controller.text);
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(response.message ?? (response.success ? '申请成功' : '申请失败'))),
|
|
);
|
|
}
|
|
},
|
|
child: const Text('确认'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showTransferDialog(AssetProvider provider) {
|
|
final controller = TextEditingController();
|
|
int direction = 1; // 1=资金转交易, 2=交易转资金
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => StatefulBuilder(
|
|
builder: (context, setState) => AlertDialog(
|
|
backgroundColor: AppColors.cardBackground,
|
|
title: const Text('划转', style: TextStyle(color: AppColors.textPrimary)),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
ChoiceChip(
|
|
label: const Text('资金→交易'),
|
|
selected: direction == 1,
|
|
onSelected: (v) => setState(() => direction = 1),
|
|
),
|
|
const SizedBox(width: 8),
|
|
ChoiceChip(
|
|
label: const Text('交易→资金'),
|
|
selected: direction == 2,
|
|
onSelected: (v) => setState(() => direction = 2),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: controller,
|
|
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
|
style: const TextStyle(color: AppColors.textPrimary),
|
|
decoration: const InputDecoration(
|
|
hintText: '请输入划转金额(USDT)',
|
|
hintStyle: TextStyle(color: AppColors.textHint),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('取消'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
Navigator.pop(context);
|
|
final response = await provider.transfer(
|
|
direction: direction,
|
|
amount: controller.text,
|
|
);
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(response.message ?? (response.success ? '划转成功' : '划转失败'))),
|
|
);
|
|
}
|
|
},
|
|
child: const Text('确认'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|