feat: 添加业务分析后端接口
新增 AnalysisController 提供 6 个分析接口: - /admin/analysis/profit - 盈利分析(交易手续费/充提手续费/资金利差) - /admin/analysis/cash-flow - 资金流动趋势(按月统计充值/提现/净流入) - /admin/analysis/trade - 交易分析(买入/卖出统计+趋势) - /admin/analysis/coin-distribution - 币种交易分布 - /admin/analysis/user-growth - 用户增长分析(新增/活跃用户) - /admin/analysis/risk - 风险指标(大额交易/异常提现/KYC/冻结账户) - /admin/analysis/health - 综合健康度评分 更新 Mapper 添加分析查询方法: - OrderFundMapper: 手续费统计、时间范围查询、大额交易、异常提现 - OrderTradeMapper: 交易金额统计、活跃用户、币种分布 前端 API 对接: - 新增 6 个分析相关 Query hooks - 更新 analytics.vue 使用真实数据 - 动态决策建议基于实际数据
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/constants/app_colors.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
|
||||
/// 资产页面
|
||||
/// 资产页面 - 使用 shadcn_ui 现代化设计
|
||||
class AssetPage extends StatefulWidget {
|
||||
const AssetPage({super.key});
|
||||
|
||||
@@ -17,6 +17,10 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
|
||||
int _activeTab = 0; // 0=资金账户, 1=交易账户
|
||||
|
||||
// 颜色常量
|
||||
static const upColor = Color(0xFF00C853);
|
||||
static const downColor = Color(0xFFFF5252);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -32,13 +36,15 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
backgroundColor: theme.colorScheme.background,
|
||||
body: Consumer<AssetProvider>(
|
||||
builder: (context, provider, _) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: provider.refreshAll,
|
||||
color: AppColors.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -61,13 +67,21 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
}
|
||||
|
||||
Widget _buildAssetCard(AssetProvider provider) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final overview = provider.overview;
|
||||
|
||||
// 自定义渐变色
|
||||
const gradientColors = [
|
||||
Color(0xFF00D4AA),
|
||||
Color(0xFF00B894),
|
||||
];
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [AppColors.primary, AppColors.primaryDark],
|
||||
colors: gradientColors,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
@@ -75,15 +89,14 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const Text(
|
||||
Text(
|
||||
'总资产估值(USDT)',
|
||||
style: TextStyle(fontSize: 14, color: Colors.white70),
|
||||
style: theme.textTheme.small.copyWith(color: Colors.white70),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
overview?.totalAsset ?? '0.00',
|
||||
style: const TextStyle(
|
||||
fontSize: 36,
|
||||
style: theme.textTheme.h1.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
@@ -92,11 +105,15 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.trending_up, color: Colors.white70, size: 16),
|
||||
Icon(
|
||||
LucideIcons.trendingUp,
|
||||
color: Colors.white70,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'总盈亏: ${overview?.totalProfit ?? '0.00'} USDT',
|
||||
style: const TextStyle(fontSize: 14, color: Colors.white70),
|
||||
style: theme.textTheme.small.copyWith(color: Colors.white70),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -106,10 +123,12 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
}
|
||||
|
||||
Widget _buildAccountTabs() {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
color: theme.colorScheme.card,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
@@ -120,15 +139,21 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: _activeTab == 0 ? AppColors.primary : Colors.transparent,
|
||||
color: _activeTab == 0
|
||||
? theme.colorScheme.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,
|
||||
color: _activeTab == 0
|
||||
? Colors.white
|
||||
: theme.colorScheme.mutedForeground,
|
||||
fontWeight: _activeTab == 0
|
||||
? FontWeight.w600
|
||||
: FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -141,15 +166,21 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: _activeTab == 1 ? AppColors.primary : Colors.transparent,
|
||||
color: _activeTab == 1
|
||||
? theme.colorScheme.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,
|
||||
color: _activeTab == 1
|
||||
? Colors.white
|
||||
: theme.colorScheme.mutedForeground,
|
||||
fontWeight: _activeTab == 1
|
||||
? FontWeight.w600
|
||||
: FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -162,99 +193,111 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
}
|
||||
|
||||
Widget _buildFundAccount(AssetProvider provider) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final fund = provider.fundAccount;
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'USDT余额',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
fund?.balance ?? '0.00',
|
||||
style: theme.textTheme.h2.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
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,
|
||||
Expanded(
|
||||
child: ShadButton(
|
||||
backgroundColor: const Color(0xFF00C853),
|
||||
onPressed: () => _showDepositDialog(provider),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(LucideIcons.plus, size: 18, color: Colors.white),
|
||||
const SizedBox(width: 4),
|
||||
const Text('充值'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
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: ShadButton(
|
||||
backgroundColor: const Color(0xFFFF9800),
|
||||
onPressed: () => _showWithdrawDialog(provider),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(LucideIcons.minus, size: 18, color: Colors.white),
|
||||
const SizedBox(width: 4),
|
||||
const Text('提现'),
|
||||
],
|
||||
),
|
||||
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: ShadButton.outline(
|
||||
onPressed: () => _showTransferDialog(provider),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(LucideIcons.arrowRightLeft, size: 18),
|
||||
const SizedBox(width: 4),
|
||||
const Text('划转'),
|
||||
],
|
||||
),
|
||||
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 theme = ShadTheme.of(context);
|
||||
final holdings = provider.holdings;
|
||||
return Container(
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
Text(
|
||||
'持仓列表',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
style: theme.textTheme.large.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (holdings.isEmpty)
|
||||
const Center(
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(32),
|
||||
child: Text(
|
||||
'暂无持仓',
|
||||
style: TextStyle(color: AppColors.textSecondary),
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.wallet,
|
||||
size: 48,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'暂无持仓',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -263,47 +306,13 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: holdings.length,
|
||||
separatorBuilder: (_, __) => const Divider(color: AppColors.border),
|
||||
separatorBuilder: (_, __) => Divider(
|
||||
color: theme.colorScheme.border,
|
||||
height: 1,
|
||||
),
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return _buildHoldingItem(holding);
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -311,145 +320,253 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHoldingItem(holding) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.1),
|
||||
child: Text(
|
||||
holding.coinCode.substring(0, 1),
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
holding.coinCode,
|
||||
style: theme.textTheme.large.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'数量: ${holding.quantity}',
|
||||
style: theme.textTheme.muted.copyWith(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${holding.currentValue} USDT',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
Text(
|
||||
holding.formattedProfitRate,
|
||||
style: TextStyle(
|
||||
color: holding.isProfit ? upColor : downColor,
|
||||
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('确认'),
|
||||
),
|
||||
],
|
||||
),
|
||||
_showActionDialog(
|
||||
title: '充值',
|
||||
hint: '请输入充值金额(USDT)',
|
||||
onSubmit: (amount) async {
|
||||
final response = await provider.deposit(amount: amount);
|
||||
if (mounted) {
|
||||
_showResult(response.success ? '申请成功' : '申请失败', response.message);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
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('确认'),
|
||||
),
|
||||
],
|
||||
),
|
||||
_showActionDialog(
|
||||
title: '提现',
|
||||
hint: '请输入提现金额(USDT)',
|
||||
onSubmit: (amount) async {
|
||||
final response = await provider.withdraw(amount: amount);
|
||||
if (mounted) {
|
||||
_showResult(response.success ? '申请成功' : '申请失败', response.message);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showTransferDialog(AssetProvider provider) {
|
||||
final controller = TextEditingController();
|
||||
int direction = 1; // 1=资金转交易, 2=交易转资金
|
||||
showDialog(
|
||||
final formKey = GlobalKey<ShadFormState>();
|
||||
int direction = 1;
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => StatefulBuilder(
|
||||
builder: (context, setState) => AlertDialog(
|
||||
backgroundColor: AppColors.cardBackground,
|
||||
title: const Text('划转', style: TextStyle(color: AppColors.textPrimary)),
|
||||
content: Column(
|
||||
builder: (context, setState) => ShadDialog(
|
||||
title: const Text('划转'),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
label: const Text('资金→交易'),
|
||||
selected: direction == 1,
|
||||
onSelected: (v) => setState(() => direction = 1),
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: () => setState(() => direction = 1),
|
||||
child: Row(
|
||||
children: [
|
||||
if (direction == 1)
|
||||
Icon(LucideIcons.check, size: 14)
|
||||
else
|
||||
const SizedBox(width: 14),
|
||||
const SizedBox(width: 4),
|
||||
const Text('资金→交易'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ChoiceChip(
|
||||
label: const Text('交易→资金'),
|
||||
selected: direction == 2,
|
||||
onSelected: (v) => setState(() => direction = 2),
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: () => setState(() => direction = 2),
|
||||
child: Row(
|
||||
children: [
|
||||
if (direction == 2)
|
||||
Icon(LucideIcons.check, size: 14)
|
||||
else
|
||||
const SizedBox(width: 14),
|
||||
const SizedBox(width: 4),
|
||||
const Text('交易→资金'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
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),
|
||||
ShadForm(
|
||||
key: formKey,
|
||||
child: ShadInputFormField(
|
||||
id: 'amount',
|
||||
controller: controller,
|
||||
placeholder: const Text('请输入划转金额(USDT)'),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入金额';
|
||||
}
|
||||
final amount = double.tryParse(value);
|
||||
if (amount == null || amount <= 0) {
|
||||
return '请输入有效金额';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ElevatedButton(
|
||||
ShadButton(
|
||||
child: const Text('确认'),
|
||||
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 ? '划转成功' : '划转失败'))),
|
||||
if (formKey.currentState!.saveAndValidate()) {
|
||||
Navigator.of(context).pop();
|
||||
final response = await provider.transfer(
|
||||
direction: direction,
|
||||
amount: controller.text,
|
||||
);
|
||||
if (mounted) {
|
||||
_showResult(
|
||||
response.success ? '划转成功' : '划转失败',
|
||||
response.message,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('确认'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showActionDialog({
|
||||
required String title,
|
||||
required String hint,
|
||||
required Function(String) onSubmit,
|
||||
}) {
|
||||
final controller = TextEditingController();
|
||||
final formKey = GlobalKey<ShadFormState>();
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog(
|
||||
title: Text(title),
|
||||
child: ShadForm(
|
||||
key: formKey,
|
||||
child: ShadInputFormField(
|
||||
id: 'amount',
|
||||
controller: controller,
|
||||
placeholder: Text(hint),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入金额';
|
||||
}
|
||||
final amount = double.tryParse(value);
|
||||
if (amount == null || amount <= 0) {
|
||||
return '请输入有效金额';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ShadButton(
|
||||
child: const Text('确认'),
|
||||
onPressed: () async {
|
||||
if (formKey.currentState!.saveAndValidate()) {
|
||||
Navigator.of(context).pop();
|
||||
onSubmit(controller.text);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showResult(String title, String? message) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: Text(title),
|
||||
description: message != null ? Text(message) : null,
|
||||
actions: [
|
||||
ShadButton(
|
||||
child: const Text('确定'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/constants/app_colors.dart';
|
||||
import '../../../providers/auth_provider.dart';
|
||||
import '../main/main_page.dart';
|
||||
import 'register_page.dart';
|
||||
|
||||
/// 登录页面
|
||||
import '../../../providers/auth_provider.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@@ -14,160 +12,155 @@ class LoginPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
final _usernameController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
bool _obscurePassword = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_usernameController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
final formKey = GlobalKey<ShadFormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const SizedBox(height: 60),
|
||||
// Logo
|
||||
const Center(
|
||||
child: Text(
|
||||
body: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 400),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: ShadForm(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Logo 和标题
|
||||
Icon(
|
||||
LucideIcons.trendingUp,
|
||||
size: 64,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'模拟所',
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
style: theme.textTheme.h1,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Center(
|
||||
child: Text(
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'虚拟货币模拟交易平台',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
style: theme.textTheme.muted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
// 用户名输入
|
||||
TextFormField(
|
||||
controller: _usernameController,
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
hintText: '请输入用户名',
|
||||
prefixIcon: const Icon(Icons.person_outline, color: AppColors.textSecondary),
|
||||
const SizedBox(height: 48),
|
||||
|
||||
// 用户名输入
|
||||
ShadInputFormField(
|
||||
id: 'username',
|
||||
label: const Text('用户名'),
|
||||
placeholder: const Text('请输入用户名'),
|
||||
leading: const Icon(LucideIcons.user),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入用户名';
|
||||
}
|
||||
if (value.length < 3) {
|
||||
return '用户名至少 3 个字符';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入用户名';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 密码输入
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: _obscurePassword,
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
hintText: '请输入密码',
|
||||
prefixIcon: const Icon(Icons.lock_outline, color: AppColors.textSecondary),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscurePassword ? Icons.visibility_off : Icons.visibility,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscurePassword = !_obscurePassword;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 密码输入
|
||||
ShadInputFormField(
|
||||
id: 'password',
|
||||
label: const Text('密码'),
|
||||
placeholder: const Text('请输入密码'),
|
||||
obscureText: true,
|
||||
leading: const Icon(LucideIcons.lock),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入密码';
|
||||
}
|
||||
if (value.length < 6) {
|
||||
return '密码至少 6 个字符';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入密码';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
// 登录按钮
|
||||
Consumer<AuthProvider>(
|
||||
builder: (context, auth, _) {
|
||||
return ElevatedButton(
|
||||
onPressed: auth.isLoading ? null : _handleLogin,
|
||||
child: auth.isLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Text('登录'),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 注册链接
|
||||
Center(
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const RegisterPage()),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 登录按钮
|
||||
Consumer<AuthProvider>(
|
||||
builder: (context, auth, _) {
|
||||
return ShadButton(
|
||||
onPressed: auth.isLoading
|
||||
? null
|
||||
: () async {
|
||||
if (formKey.currentState!.saveAndValidate()) {
|
||||
final values = formKey.currentState!.value;
|
||||
final response = await auth.login(
|
||||
values['username'],
|
||||
values['password'],
|
||||
);
|
||||
|
||||
// 登录成功后,Provider 会自动更新状态
|
||||
// MaterialApp 的 Consumer 会自动切换到 MainPage
|
||||
if (!response.success && mounted) {
|
||||
// 只在失败时显示错误
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: const Text('登录失败'),
|
||||
description: Text(
|
||||
response.message ?? '用户名或密码错误',
|
||||
),
|
||||
actions: [
|
||||
ShadButton(
|
||||
child: const Text('确定'),
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: auth.isLoading
|
||||
? const SizedBox.square(
|
||||
dimension: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Text('登录'),
|
||||
);
|
||||
},
|
||||
child: const Text(
|
||||
'还没有账号?立即注册',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 注册链接
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'还没有账号?',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
ShadButton.link(
|
||||
onPressed: () {
|
||||
// 跳转到注册页面
|
||||
// context.go('/register');
|
||||
},
|
||||
child: const Text('立即注册'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleLogin() async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
|
||||
final auth = context.read<AuthProvider>();
|
||||
final response = await auth.login(
|
||||
_usernameController.text.trim(),
|
||||
_passwordController.text,
|
||||
);
|
||||
|
||||
if (response.success && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('登录成功')),
|
||||
);
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const MainPage()),
|
||||
);
|
||||
} else if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(response.message ?? '登录失败')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../providers/auth_provider.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
State<LoginPage> createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
final formKey = GlobalKey<ShadFormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 400),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: ShadForm(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Logo 和标题
|
||||
Icon(
|
||||
LucideIcons.trendingUp,
|
||||
size: 64,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'模拟所',
|
||||
style: theme.textTheme.h1,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'虚拟货币模拟交易平台',
|
||||
style: theme.textTheme.muted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
|
||||
// 用户名输入
|
||||
ShadInputFormField(
|
||||
id: 'username',
|
||||
label: const Text('用户名'),
|
||||
placeholder: const Text('请输入用户名'),
|
||||
leading: const Icon(LucideIcons.user),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入用户名';
|
||||
}
|
||||
if (value.length < 3) {
|
||||
return '用户名至少 3 个字符';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 密码输入
|
||||
ShadInputFormField(
|
||||
id: 'password',
|
||||
label: const Text('密码'),
|
||||
placeholder: const Text('请输入密码'),
|
||||
obscureText: true,
|
||||
leading: const Icon(LucideIcons.lock),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入密码';
|
||||
}
|
||||
if (value.length < 6) {
|
||||
return '密码至少 6 个字符';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 登录按钮
|
||||
Consumer<AuthProvider>(
|
||||
builder: (context, auth, _) {
|
||||
return ShadButton(
|
||||
onPressed: auth.isLoading
|
||||
? null
|
||||
: () async {
|
||||
if (formKey.currentState!.saveAndValidate()) {
|
||||
final values = formKey.currentState!.value;
|
||||
final success = await auth.login(
|
||||
values['username'],
|
||||
values['password'],
|
||||
);
|
||||
|
||||
if (!success && mounted) {
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: const Text('登录失败'),
|
||||
description: Text(
|
||||
auth.error ?? '用户名或密码错误',
|
||||
),
|
||||
actions: [
|
||||
ShadButton(
|
||||
child: const Text('确定'),
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: auth.isLoading
|
||||
? const SizedBox.square(
|
||||
dimension: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Text('登录'),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 注册链接
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'还没有账号?',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
ShadButton.link(
|
||||
onPressed: () {
|
||||
// 跳转到注册页面
|
||||
// context.go('/register');
|
||||
},
|
||||
child: const Text('立即注册'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/constants/app_colors.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
import '../../../providers/auth_provider.dart';
|
||||
import '../asset/asset_page.dart';
|
||||
import '../trade/trade_page.dart';
|
||||
|
||||
/// 首页
|
||||
/// 首页 - 使用 shadcn_ui 现代化设计
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@@ -35,13 +33,15 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
backgroundColor: theme.colorScheme.background,
|
||||
body: Consumer<AssetProvider>(
|
||||
builder: (context, provider, _) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () => provider.refreshAll(),
|
||||
color: AppColors.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -66,6 +66,8 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Consumer<AuthProvider>(
|
||||
builder: (context, auth, _) {
|
||||
final user = auth.user;
|
||||
@@ -73,11 +75,11 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: AppColors.primary.withOpacity(0.2),
|
||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.2),
|
||||
child: Text(
|
||||
user?.avatarText ?? 'U',
|
||||
style: const TextStyle(
|
||||
color: AppColors.primary,
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@@ -89,37 +91,40 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
children: [
|
||||
Text(
|
||||
'你好,${user?.username ?? '用户'}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
style: theme.textTheme.large.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
const Text(
|
||||
Text(
|
||||
'欢迎来到模拟所',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
).animate().fadeIn(duration: 300.ms).slideX(begin: -0.1, end: 0);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAssetCard(AssetProvider provider) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final overview = provider.overview;
|
||||
|
||||
// 自定义渐变色
|
||||
const gradientColors = [
|
||||
Color(0xFF00D4AA),
|
||||
Color(0xFF00B894),
|
||||
];
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [AppColors.primary, AppColors.primaryDark],
|
||||
colors: gradientColors,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
@@ -128,20 +133,16 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
Text(
|
||||
'总资产(USDT)',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.white70,
|
||||
),
|
||||
style: theme.textTheme.small.copyWith(color: Colors.white70),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
overview?.totalAsset ?? '0.00',
|
||||
style: const TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
style: theme.textTheme.h2.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
@@ -154,7 +155,7 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
).animate().fadeIn(duration: 400.ms).slideY(begin: 0.1, end: 0);
|
||||
}
|
||||
|
||||
Widget _buildAssetItem(String label, String value) {
|
||||
@@ -179,25 +180,48 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
}
|
||||
|
||||
Widget _buildQuickActions() {
|
||||
return Container(
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildActionItem('充', '充值', AppColors.success, () => _showDeposit()),
|
||||
_buildActionItem('提', '提现', AppColors.warning, () => _showWithdraw()),
|
||||
_buildActionItem('转', '划转', AppColors.primary, () => _showTransfer()),
|
||||
_buildActionItem('币', '交易', AppColors.info, () => _navigateToTrade()),
|
||||
_buildActionItem(
|
||||
icon: LucideIcons.arrowDownToLine,
|
||||
text: '充值',
|
||||
color: const Color(0xFF00C853),
|
||||
onTap: () => _showDeposit(),
|
||||
),
|
||||
_buildActionItem(
|
||||
icon: LucideIcons.arrowUpFromLine,
|
||||
text: '提现',
|
||||
color: const Color(0xFFFF9800),
|
||||
onTap: () => _showWithdraw(),
|
||||
),
|
||||
_buildActionItem(
|
||||
icon: LucideIcons.arrowRightLeft,
|
||||
text: '划转',
|
||||
color: theme.colorScheme.primary,
|
||||
onTap: () => _showTransfer(),
|
||||
),
|
||||
_buildActionItem(
|
||||
icon: LucideIcons.trendingUp,
|
||||
text: '交易',
|
||||
color: const Color(0xFF2196F3),
|
||||
onTap: () => _navigateToTrade(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
).animate().fadeIn(duration: 500.ms, delay: 100.ms);
|
||||
}
|
||||
|
||||
Widget _buildActionItem(String icon, String text, Color color, VoidCallback onTap) {
|
||||
Widget _buildActionItem({
|
||||
required IconData icon,
|
||||
required String text,
|
||||
required Color color,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Column(
|
||||
@@ -209,23 +233,14 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
color: color.withOpacity(0.15),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
icon,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: color,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 22),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textPrimary,
|
||||
color: ShadTheme.of(context).colorScheme.foreground,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -234,61 +249,51 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
}
|
||||
|
||||
Widget _buildHoldings(AssetProvider provider) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final holdings = provider.holdings;
|
||||
return Container(
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Row(
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'我的持仓',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
style: theme.textTheme.large.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
color: AppColors.textSecondary,
|
||||
LucideIcons.chevronRight,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (holdings.isEmpty)
|
||||
const Center(
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(32),
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.account_balance_wallet_outlined,
|
||||
LucideIcons.wallet,
|
||||
size: 48,
|
||||
color: AppColors.textHint,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'暂无持仓',
|
||||
style: TextStyle(
|
||||
color: AppColors.textSecondary,
|
||||
fontSize: 14,
|
||||
),
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'快去交易吧~',
|
||||
style: TextStyle(
|
||||
color: AppColors.textHint,
|
||||
fontSize: 12,
|
||||
),
|
||||
style: theme.textTheme.muted.copyWith(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -299,18 +304,27 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: holdings.length > 5 ? 5 : holdings.length,
|
||||
separatorBuilder: (_, __) => const Divider(color: AppColors.border),
|
||||
separatorBuilder: (_, __) => Divider(
|
||||
color: theme.colorScheme.border,
|
||||
height: 1,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final holding = holdings[index];
|
||||
return _buildHoldingItem(holding);
|
||||
return _buildHoldingItem(holding)
|
||||
.animate()
|
||||
.fadeIn(delay: Duration(milliseconds: 50 * index));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
).animate().fadeIn(duration: 500.ms, delay: 200.ms);
|
||||
}
|
||||
|
||||
Widget _buildHoldingItem(holding) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final upColor = const Color(0xFF00C853);
|
||||
final downColor = const Color(0xFFFF5252);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
@@ -318,20 +332,14 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
holding.coinCode.substring(0, 1),
|
||||
style: const TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
CircleAvatar(
|
||||
radius: 18,
|
||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.1),
|
||||
child: Text(
|
||||
holding.coinCode.substring(0, 1),
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -341,18 +349,13 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
children: [
|
||||
Text(
|
||||
holding.coinCode,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
style: theme.textTheme.large.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
holding.quantity,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -363,15 +366,14 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
children: [
|
||||
Text(
|
||||
'${holding.currentValue} USDT',
|
||||
style: const TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
holding.formattedProfitRate,
|
||||
style: TextStyle(
|
||||
color: holding.isProfit ? AppColors.up : AppColors.down,
|
||||
color: holding.isProfit ? upColor : downColor,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
@@ -383,21 +385,18 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
}
|
||||
|
||||
void _showDeposit() {
|
||||
// 显示充值弹窗
|
||||
_showActionDialog('充值', '请输入充值金额(USDT)', (amount) {
|
||||
context.read<AssetProvider>().deposit(amount: amount);
|
||||
});
|
||||
}
|
||||
|
||||
void _showWithdraw() {
|
||||
// 显示提现弹窗
|
||||
_showActionDialog('提现', '请输入提现金额(USDT)', (amount) {
|
||||
context.read<AssetProvider>().withdraw(amount: amount);
|
||||
});
|
||||
}
|
||||
|
||||
void _showTransfer() {
|
||||
// 显示划转弹窗
|
||||
_showActionDialog('划转', '请输入划转金额(USDT)', (amount) {
|
||||
context.read<AssetProvider>().transfer(direction: 1, amount: amount);
|
||||
});
|
||||
@@ -405,31 +404,44 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
|
||||
void _showActionDialog(String title, String hint, Function(String) onSubmit) {
|
||||
final controller = TextEditingController();
|
||||
showDialog(
|
||||
final formKey = GlobalKey<ShadFormState>();
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: AppColors.cardBackground,
|
||||
title: Text(title, style: const TextStyle(color: AppColors.textPrimary)),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
hintText: hint,
|
||||
hintStyle: const TextStyle(color: AppColors.textHint),
|
||||
builder: (context) => ShadDialog(
|
||||
title: Text(title),
|
||||
child: ShadForm(
|
||||
key: formKey,
|
||||
child: ShadInputFormField(
|
||||
id: 'amount',
|
||||
placeholder: Text(hint),
|
||||
controller: controller,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入金额';
|
||||
}
|
||||
final amount = double.tryParse(value);
|
||||
if (amount == null || amount <= 0) {
|
||||
return '请输入有效金额';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
onSubmit(controller.text);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
ShadButton(
|
||||
child: const Text('确认'),
|
||||
onPressed: () {
|
||||
if (formKey.currentState!.saveAndValidate()) {
|
||||
onSubmit(controller.text);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -437,6 +449,6 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
}
|
||||
|
||||
void _navigateToTrade() {
|
||||
// 切换到交易页
|
||||
// 切换到交易页 - 通过 MainController
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/constants/app_colors.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import '../home/home_page.dart';
|
||||
import '../market/market_page.dart';
|
||||
import '../trade/trade_page.dart';
|
||||
import '../asset/asset_page.dart';
|
||||
import '../mine/mine_page.dart';
|
||||
|
||||
/// 主页面(包含底部导航)
|
||||
/// 主页面(使用 shadcn_ui 风格)
|
||||
class MainPage extends StatefulWidget {
|
||||
const MainPage({super.key});
|
||||
|
||||
@@ -26,66 +26,71 @@ class _MainPageState extends State<MainPage> {
|
||||
];
|
||||
|
||||
final List<_TabItem> _tabs = [
|
||||
_TabItem('首页', Icons.home_outlined, Icons.home),
|
||||
_TabItem('行情', Icons.show_chart_outlined, Icons.show_chart),
|
||||
_TabItem('交易', Icons.swap_horiz_outlined, Icons.swap_horiz),
|
||||
_TabItem('资产', Icons.account_balance_wallet_outlined, Icons.account_balance_wallet),
|
||||
_TabItem('我的', Icons.person_outline, Icons.person),
|
||||
_TabItem('首页', LucideIcons.house, LucideIcons.house),
|
||||
_TabItem('行情', LucideIcons.trendingUp, LucideIcons.trendingUp),
|
||||
_TabItem('交易', LucideIcons.arrowLeftRight, LucideIcons.arrowLeftRight),
|
||||
_TabItem('资产', LucideIcons.wallet, LucideIcons.wallet),
|
||||
_TabItem('我的', LucideIcons.user, LucideIcons.user),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
body: IndexedStack(
|
||||
index: _currentIndex,
|
||||
children: _pages,
|
||||
),
|
||||
bottomNavigationBar: _buildBottomNav(),
|
||||
);
|
||||
}
|
||||
bottomNavigationBar: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.background,
|
||||
border: Border(
|
||||
top: BorderSide(color: theme.colorScheme.border),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: _tabs.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final tab = entry.value;
|
||||
final isSelected = index == _currentIndex;
|
||||
|
||||
Widget _buildBottomNav() {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
border: Border(top: BorderSide(color: AppColors.border)),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: _tabs.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final tab = entry.value;
|
||||
final isSelected = index == _currentIndex;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => setState(() => _currentIndex = index),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
isSelected ? tab.selectedIcon : tab.icon,
|
||||
color: isSelected ? AppColors.primary : AppColors.textSecondary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
tab.label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isSelected ? AppColors.primary : AppColors.textSecondary,
|
||||
return GestureDetector(
|
||||
onTap: () => setState(() => _currentIndex = index),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
tab.icon,
|
||||
color: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.mutedForeground,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
tab.label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.mutedForeground,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/constants/app_colors.dart';
|
||||
import '../../../data/models/coin.dart';
|
||||
import '../../../providers/market_provider.dart';
|
||||
|
||||
/// 行情页面
|
||||
/// 行情页面 - 使用 shadcn_ui 现代化设计
|
||||
class MarketPage extends StatefulWidget {
|
||||
const MarketPage({super.key});
|
||||
|
||||
@@ -35,8 +35,10 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
backgroundColor: theme.colorScheme.background,
|
||||
body: Consumer<MarketProvider>(
|
||||
builder: (context, provider, _) {
|
||||
return Column(
|
||||
@@ -54,30 +56,39 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
|
||||
}
|
||||
|
||||
Widget _buildSearchBar(MarketProvider provider) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: TextField(
|
||||
child: ShadInput(
|
||||
controller: _searchController,
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
onChanged: provider.search,
|
||||
decoration: InputDecoration(
|
||||
hintText: '搜索币种...',
|
||||
prefixIcon: const Icon(Icons.search, color: AppColors.textSecondary),
|
||||
suffixIcon: _searchController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear, color: AppColors.textSecondary),
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
provider.clearSearch();
|
||||
},
|
||||
)
|
||||
: null,
|
||||
placeholder: const Text('搜索币种...'),
|
||||
leading: Icon(
|
||||
LucideIcons.search,
|
||||
size: 18,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
trailing: _searchController.text.isNotEmpty
|
||||
? GestureDetector(
|
||||
onTap: () {
|
||||
_searchController.clear();
|
||||
provider.clearSearch();
|
||||
},
|
||||
child: Icon(
|
||||
LucideIcons.x,
|
||||
size: 18,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
onChanged: provider.search,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabs(MarketProvider provider) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
final tabs = [
|
||||
{'key': 'all', 'label': '全部'},
|
||||
{'key': 'realtime', 'label': '实时'},
|
||||
@@ -88,21 +99,28 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
|
||||
height: 44,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
children: tabs.map((tab) {
|
||||
children: tabs.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final tab = entry.value;
|
||||
final isActive = provider.activeTab == tab['key'];
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => provider.setTab(tab['key']!),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
margin: const EdgeInsets.only(right: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? AppColors.primary : AppColors.cardBackground,
|
||||
color: isActive
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.card,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
tab['label']!,
|
||||
style: TextStyle(
|
||||
color: isActive ? Colors.white : AppColors.textSecondary,
|
||||
color: isActive
|
||||
? Colors.white
|
||||
: theme.colorScheme.mutedForeground,
|
||||
fontWeight: isActive ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
@@ -114,9 +132,13 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
|
||||
}
|
||||
|
||||
Widget _buildCoinList(MarketProvider provider) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
if (provider.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -125,9 +147,18 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(provider.error!, style: const TextStyle(color: AppColors.error)),
|
||||
Icon(
|
||||
LucideIcons.circleAlert,
|
||||
size: 48,
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
provider.error!,
|
||||
style: TextStyle(color: theme.colorScheme.destructive),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
ShadButton(
|
||||
onPressed: provider.loadCoins,
|
||||
child: const Text('重试'),
|
||||
),
|
||||
@@ -138,14 +169,28 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
|
||||
|
||||
final coins = provider.coins;
|
||||
if (coins.isEmpty) {
|
||||
return const Center(
|
||||
child: Text('暂无数据', style: TextStyle(color: AppColors.textSecondary)),
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.coins,
|
||||
size: 48,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'暂无数据',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: provider.refresh,
|
||||
color: AppColors.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
itemCount: coins.length,
|
||||
@@ -155,73 +200,64 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
|
||||
}
|
||||
|
||||
Widget _buildCoinItem(Coin coin) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// 图标
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
),
|
||||
child: Center(
|
||||
final theme = ShadTheme.of(context);
|
||||
final upColor = const Color(0xFF00C853);
|
||||
final downColor = const Color(0xFFFF5252);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
// 图标
|
||||
CircleAvatar(
|
||||
radius: 22,
|
||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.1),
|
||||
child: Text(
|
||||
coin.displayIcon,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: AppColors.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 名称
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${coin.code}/USDT',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
const SizedBox(width: 12),
|
||||
// 名称
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${coin.code}/USDT',
|
||||
style: theme.textTheme.large.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
coin.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textSecondary,
|
||||
Text(
|
||||
coin.name,
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// 涨跌幅
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: coin.isUp ? AppColors.up.withOpacity(0.2) : AppColors.down.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
coin.formattedChange,
|
||||
style: TextStyle(
|
||||
color: coin.isUp ? AppColors.up : AppColors.down,
|
||||
fontWeight: FontWeight.w600,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
// 涨跌幅
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: coin.isUp ? upColor.withValues(alpha: 0.2) : downColor.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
coin.formattedChange,
|
||||
style: TextStyle(
|
||||
color: coin.isUp ? upColor : downColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/constants/app_colors.dart';
|
||||
import '../../../providers/auth_provider.dart';
|
||||
|
||||
/// 我的页面
|
||||
/// 我的页面 - 使用 shadcn_ui 现代化设计
|
||||
class MinePage extends StatefulWidget {
|
||||
const MinePage({super.key});
|
||||
|
||||
@@ -18,8 +18,10 @@ class _MinePageState extends State<MinePage> with AutomaticKeepAliveClientMixin
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
backgroundColor: theme.colorScheme.background,
|
||||
body: Consumer<AuthProvider>(
|
||||
builder: (context, auth, _) {
|
||||
final user = auth.user;
|
||||
@@ -41,22 +43,20 @@ class _MinePageState extends State<MinePage> with AutomaticKeepAliveClientMixin
|
||||
}
|
||||
|
||||
Widget _buildUserCard(user) {
|
||||
return Container(
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 32,
|
||||
backgroundColor: AppColors.primary.withOpacity(0.2),
|
||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.2),
|
||||
child: Text(
|
||||
user?.avatarText ?? 'U',
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: AppColors.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@@ -68,174 +68,307 @@ class _MinePageState extends State<MinePage> with AutomaticKeepAliveClientMixin
|
||||
children: [
|
||||
Text(
|
||||
user?.username ?? '未登录',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
style: theme.textTheme.h3.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
ShadBadge(
|
||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.2),
|
||||
child: Text(
|
||||
'普通用户',
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: AppColors.textSecondary),
|
||||
Icon(
|
||||
LucideIcons.chevronRight,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMenuList(BuildContext context, AuthProvider auth) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
final menuItems = [
|
||||
_MenuItem(
|
||||
icon: LucideIcons.userCheck,
|
||||
title: '实名认证',
|
||||
subtitle: '完成实名认证,解锁更多功能',
|
||||
onTap: () => _showComingSoon('实名认证'),
|
||||
),
|
||||
_MenuItem(
|
||||
icon: LucideIcons.shield,
|
||||
title: '安全设置',
|
||||
subtitle: '密码、二次验证等安全设置',
|
||||
onTap: () => _showComingSoon('安全设置'),
|
||||
),
|
||||
_MenuItem(
|
||||
icon: LucideIcons.bell,
|
||||
title: '消息通知',
|
||||
subtitle: '管理消息推送设置',
|
||||
onTap: () => _showComingSoon('消息通知'),
|
||||
),
|
||||
_MenuItem(
|
||||
icon: LucideIcons.settings,
|
||||
title: '系统设置',
|
||||
subtitle: '主题、语言等偏好设置',
|
||||
onTap: () => _showComingSoon('系统设置'),
|
||||
),
|
||||
_MenuItem(
|
||||
icon: LucideIcons.info,
|
||||
title: '关于我们',
|
||||
subtitle: '版本信息与用户协议',
|
||||
onTap: () => _showAboutDialog(),
|
||||
),
|
||||
];
|
||||
|
||||
return ShadCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildMenuItem(Icons.verified_user, '实名认证', () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('功能开发中')),
|
||||
);
|
||||
}),
|
||||
const Divider(color: AppColors.border, height: 1),
|
||||
_buildMenuItem(Icons.security, '安全设置', () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('功能开发中')));
|
||||
}),
|
||||
const Divider(color: AppColors.border, height: 1),
|
||||
_buildMenuItem(Icons.info_outline, '关于我们', () {
|
||||
showAboutDialog(context);
|
||||
}),
|
||||
],
|
||||
children: menuItems.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final item = entry.value;
|
||||
final isLast = index == menuItems.length - 1;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_buildMenuItem(item, index),
|
||||
if (!isLast)
|
||||
Divider(
|
||||
color: theme.colorScheme.border,
|
||||
height: 1,
|
||||
indent: 56,
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMenuItem(IconData icon, String title, VoidCallback onTap) {
|
||||
return ListTile(
|
||||
leading: Icon(icon, color: AppColors.primary),
|
||||
title: Text(
|
||||
title,
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
),
|
||||
trailing: const Icon(Icons.chevron_right, color: AppColors.textSecondary),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
Widget _buildMenuItem(_MenuItem item, int index) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
Widget _buildLogoutButton(BuildContext context, AuthProvider auth) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.error.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TextButton(
|
||||
onPressed: () => _showLogoutDialog(context, auth),
|
||||
child: const Text(
|
||||
'退出登录',
|
||||
style: TextStyle(
|
||||
color: AppColors.error,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showLogoutDialog(BuildContext context, AuthProvider auth) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: AppColors.cardBackground,
|
||||
title: const Text('确认退出', style: TextStyle(color: AppColors.textPrimary)),
|
||||
content: const Text(
|
||||
'确定要退出登录吗?',
|
||||
style: TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.error,
|
||||
),
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
await auth.logout();
|
||||
if (context.mounted) {
|
||||
Navigator.pushReplacementNamed(context, '/login');
|
||||
}
|
||||
},
|
||||
child: const Text('退出'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showAboutDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: AppColors.cardBackground,
|
||||
title: Row(
|
||||
return InkWell(
|
||||
onTap: item.onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: theme.colorScheme.primary.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text('₿', style: TextStyle(fontSize: 20, color: AppColors.primary)),
|
||||
child: Icon(
|
||||
item.icon,
|
||||
size: 20,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text('模拟所', style: TextStyle(color: AppColors.textPrimary)),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.title,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
if (item.subtitle != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
item.subtitle!,
|
||||
style: theme.textTheme.muted.copyWith(fontSize: 11),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
LucideIcons.chevronRight,
|
||||
size: 18,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
],
|
||||
),
|
||||
content: const Column(
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLogoutButton(BuildContext context, AuthProvider auth) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: ShadButton.destructive(
|
||||
onPressed: () => _showLogoutDialog(context, auth),
|
||||
child: const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(LucideIcons.logOut, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'退出登录',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showComingSoon(String feature) {
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: const Row(
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.construction,
|
||||
color: Color(0xFFFF9800),
|
||||
size: 20,
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Text('功能开发中'),
|
||||
],
|
||||
),
|
||||
description: Text('$feature功能正在开发中,敬请期待~'),
|
||||
actions: [
|
||||
ShadButton(
|
||||
child: const Text('知道了'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showLogoutDialog(BuildContext context, AuthProvider auth) {
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: const Text('确认退出'),
|
||||
description: const Text('确定要退出登录吗?'),
|
||||
actions: [
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ShadButton.destructive(
|
||||
child: const Text('退出'),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
await auth.logout();
|
||||
if (context.mounted) {
|
||||
Navigator.pushReplacementNamed(context, '/login');
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAboutDialog() {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.2),
|
||||
child: Text(
|
||||
'₿',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text('模拟所'),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'虚拟货币模拟交易平台',
|
||||
style: TextStyle(color: AppColors.textSecondary),
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'版本: 1.0.0',
|
||||
style: TextStyle(color: AppColors.textHint, fontSize: 12),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.code,
|
||||
size: 14,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'版本: 1.0.0',
|
||||
style: theme.textTheme.muted.copyWith(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.heart,
|
||||
size: 14,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'Built with Flutter & shadcn_ui',
|
||||
style: theme.textTheme.muted.copyWith(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
ShadButton(
|
||||
child: const Text('确定'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MenuItem {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final VoidCallback onTap;
|
||||
|
||||
_MenuItem({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
required this.onTap,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/constants/app_colors.dart';
|
||||
import '../../../data/models/coin.dart';
|
||||
import '../../../providers/market_provider.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
|
||||
/// 交易页面
|
||||
/// 交易页面 - 使用 shadcn_ui 现代化设计
|
||||
class TradePage extends StatefulWidget {
|
||||
const TradePage({super.key});
|
||||
|
||||
@@ -19,9 +19,14 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
|
||||
int _tradeType = 0; // 0=买入, 1=卖出
|
||||
Coin? _selectedCoin;
|
||||
final _formKey = GlobalKey<ShadFormState>();
|
||||
final _priceController = TextEditingController();
|
||||
final _quantityController = TextEditingController();
|
||||
|
||||
// 颜色常量
|
||||
static const upColor = Color(0xFF00C853);
|
||||
static const downColor = Color(0xFFFF5252);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -45,22 +50,27 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
backgroundColor: theme.colorScheme.background,
|
||||
body: Consumer2<MarketProvider, AssetProvider>(
|
||||
builder: (context, market, asset, _) {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildCoinSelector(market),
|
||||
const SizedBox(height: 16),
|
||||
_buildPriceCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildTradeForm(asset),
|
||||
const SizedBox(height: 16),
|
||||
_buildTradeButton(),
|
||||
],
|
||||
child: ShadForm(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildCoinSelector(market),
|
||||
const SizedBox(height: 16),
|
||||
_buildPriceCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildTradeForm(asset),
|
||||
const SizedBox(height: 16),
|
||||
_buildTradeButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -69,31 +79,26 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
}
|
||||
|
||||
Widget _buildCoinSelector(MarketProvider market) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final coins = market.allCoins;
|
||||
|
||||
if (_selectedCoin == null && coins.isNotEmpty) {
|
||||
_selectedCoin = coins.first;
|
||||
_priceController.text = _selectedCoin!.formattedPrice;
|
||||
}
|
||||
|
||||
return Container(
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_selectedCoin?.displayIcon ?? '?',
|
||||
style: const TextStyle(fontSize: 20, color: AppColors.primary),
|
||||
CircleAvatar(
|
||||
radius: 22,
|
||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.1),
|
||||
child: Text(
|
||||
_selectedCoin?.displayIcon ?? '?',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -104,87 +109,82 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
children: [
|
||||
Text(
|
||||
_selectedCoin != null ? '${_selectedCoin!.code}/USDT' : '选择币种',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
style: theme.textTheme.large.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_selectedCoin != null ? _selectedCoin!.name : '点击选择交易对',
|
||||
style: const TextStyle(fontSize: 12, color: AppColors.textSecondary),
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: AppColors.textSecondary),
|
||||
Icon(
|
||||
LucideIcons.chevronRight,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPriceCard() {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
if (_selectedCoin == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final coin = _selectedCoin!;
|
||||
return Container(
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('最新价', style: TextStyle(fontSize: 12, color: AppColors.textSecondary)),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'\$${coin.formattedPrice}',
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
Text(
|
||||
'最新价',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: coin.isUp ? AppColors.up.withOpacity(0.2) : AppColors.down.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
coin.formattedChange,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: coin.isUp ? AppColors.up : AppColors.down,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'\$${coin.formattedPrice}',
|
||||
style: theme.textTheme.h2.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: coin.isUp ? upColor.withValues(alpha: 0.2) : downColor.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
coin.formattedChange,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: coin.isUp ? upColor : downColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTradeForm(AssetProvider asset) {
|
||||
return Container(
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// 买入/卖出切换
|
||||
@@ -196,14 +196,15 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: _tradeType == 0 ? AppColors.up : Colors.transparent,
|
||||
color: _tradeType == 0 ? upColor : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: _tradeType != 0 ? Border.all(color: upColor) : null,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'买入',
|
||||
style: TextStyle(
|
||||
color: _tradeType == 0 ? Colors.white : AppColors.up,
|
||||
color: _tradeType == 0 ? Colors.white : upColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
@@ -218,14 +219,15 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: _tradeType == 1 ? AppColors.down : Colors.transparent,
|
||||
color: _tradeType == 1 ? downColor : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: _tradeType != 1 ? Border.all(color: downColor) : null,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'卖出',
|
||||
style: TextStyle(
|
||||
color: _tradeType == 1 ? Colors.white : AppColors.down,
|
||||
color: _tradeType == 1 ? Colors.white : downColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
@@ -237,35 +239,64 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// 价格输入
|
||||
TextField(
|
||||
ShadInputFormField(
|
||||
id: 'price',
|
||||
label: const Text('价格(USDT)'),
|
||||
controller: _priceController,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
decoration: const InputDecoration(
|
||||
labelText: '价格(USDT)',
|
||||
suffixText: 'USDT',
|
||||
placeholder: const Text('输入价格'),
|
||||
trailing: const Padding(
|
||||
padding: EdgeInsets.only(right: 8),
|
||||
child: Text('USDT'),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入价格';
|
||||
}
|
||||
final price = double.tryParse(value);
|
||||
if (price == null || price <= 0) {
|
||||
return '请输入有效价格';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 数量输入
|
||||
TextField(
|
||||
ShadInputFormField(
|
||||
id: 'quantity',
|
||||
label: const Text('数量'),
|
||||
controller: _quantityController,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
labelText: '数量',
|
||||
suffixText: _selectedCoin?.code ?? '',
|
||||
placeholder: const Text('输入数量'),
|
||||
trailing: Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: Text(_selectedCoin?.code ?? ''),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入数量';
|
||||
}
|
||||
final quantity = double.tryParse(value);
|
||||
if (quantity == null || quantity <= 0) {
|
||||
return '请输入有效数量';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const SizedBox(height: 16),
|
||||
// 交易金额
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('交易金额', style: TextStyle(color: AppColors.textSecondary)),
|
||||
Text(
|
||||
'交易金额',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
Text(
|
||||
'${_calculateAmount()} USDT',
|
||||
style: const TextStyle(color: AppColors.textPrimary, fontWeight: FontWeight.w600),
|
||||
style: theme.textTheme.small.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -274,10 +305,13 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('可用', style: TextStyle(color: AppColors.textSecondary)),
|
||||
Text(
|
||||
'可用',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
Text(
|
||||
'${asset.overview?.tradeBalance ?? '0.00'} USDT',
|
||||
style: const TextStyle(color: AppColors.textSecondary),
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -294,23 +328,99 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
|
||||
Widget _buildTradeButton() {
|
||||
final isBuy = _tradeType == 0;
|
||||
return Container(
|
||||
final color = isBuy ? upColor : downColor;
|
||||
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
gradient: isBuy ? AppColors.buyGradient : AppColors.sellGradient,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
isBuy ? '买入 ${_selectedCoin?.code ?? ''}' : '卖出 ${_selectedCoin?.code ?? ''}',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
child: ShadButton(
|
||||
backgroundColor: color,
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.saveAndValidate()) {
|
||||
_executeTrade();
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
isBuy ? LucideIcons.arrowDownToLine : LucideIcons.arrowUpFromLine,
|
||||
size: 18,
|
||||
color: Colors.white,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${isBuy ? '买入' : '卖出'} ${_selectedCoin?.code ?? ''}',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _executeTrade() {
|
||||
final price = _priceController.text;
|
||||
final quantity = _quantityController.text;
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: Text(_tradeType == 0 ? '确认买入' : '确认卖出'),
|
||||
description: Text(
|
||||
'${_tradeType == 0 ? '买入' : '卖出'} $quantity ${_selectedCoin?.code ?? ''} @ $price USDT',
|
||||
),
|
||||
actions: [
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ShadButton(
|
||||
child: const Text('确认'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
_showTradeResult();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showTradeResult() {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.circleCheck,
|
||||
color: theme.colorScheme.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('交易成功'),
|
||||
],
|
||||
),
|
||||
description: Text(
|
||||
'已${_tradeType == 0 ? '买入' : '卖出'} ${_quantityController.text} ${_selectedCoin?.code ?? ''}',
|
||||
),
|
||||
actions: [
|
||||
ShadButton(
|
||||
child: const Text('确定'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
_quantityController.clear();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user