feat: 优化交易账户和币种选择功能

- 交易账户卡片添加总市值显示和持仓列表
- 持仓列表USDT自动排在最上面
- 交易页面添加币种选择弹窗功能
- 行情页面点击币种跳转到交易页面
- 支持从外部传入选中币种参数

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
sion
2026-03-25 23:59:50 +08:00
parent 56142ed5f2
commit 396b81d6d9
4 changed files with 434 additions and 144 deletions

View File

@@ -63,7 +63,10 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
SizedBox(height: AppSpacing.md),
_activeTab == 0
? _FundAccountCard(provider: provider)
: _TradeAccountCard(holdings: provider.holdings),
: _TradeAccountCard(
holdings: provider.holdings,
tradeBalance: provider.overview?.tradeBalance,
),
],
),
),
@@ -327,40 +330,116 @@ class _FundAccountCard extends StatelessWidget {
/// 交易账户卡片 - Glass Panel 风格
class _TradeAccountCard extends StatelessWidget {
final List holdings;
final String? tradeBalance;
const _TradeAccountCard({required this.holdings});
const _TradeAccountCard({required this.holdings, this.tradeBalance});
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final isDark = Theme.of(context).brightness == Brightness.dark;
// 计算总市值所有持仓折算成USDT
double totalValue = 0;
for (var h in holdings) {
final value = double.tryParse(h.currentValue?.toString() ?? '0') ?? 0;
totalValue += value;
}
// 对持仓进行排序USDT 放在最上面
final sortedHoldings = List.from(holdings);
sortedHoldings.sort((a, b) {
final codeA = (a.coinCode ?? a['coinCode'] ?? '').toString().toUpperCase();
final codeB = (b.coinCode ?? b['coinCode'] ?? '').toString().toUpperCase();
if (codeA == 'USDT') return -1;
if (codeB == 'USDT') return 1;
return 0;
});
return GlassPanel(
padding: AppSpacing.cardPadding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题行
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: colorScheme.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(AppRadius.md),
),
child: Icon(
LucideIcons.trendingUp,
size: 18,
color: colorScheme.primary,
),
),
SizedBox(width: AppSpacing.sm),
Text(
'交易账户',
style: GoogleFonts.spaceGrotesk(
fontSize: 16,
fontWeight: FontWeight.bold,
color: colorScheme.onSurface,
),
),
],
),
Icon(
LucideIcons.chevronRight,
size: 14,
color: colorScheme.primary,
),
],
),
SizedBox(height: AppSpacing.md),
// 总市值
Text(
'持仓列表',
'总市值 (USDT)',
style: TextStyle(
fontSize: 11,
color: colorScheme.onSurfaceVariant,
),
),
SizedBox(height: AppSpacing.xs),
Text(
totalValue.toStringAsFixed(2),
style: GoogleFonts.spaceGrotesk(
fontSize: 16,
fontSize: 28,
fontWeight: FontWeight.bold,
color: colorScheme.onSurface,
),
),
SizedBox(height: AppSpacing.lg),
// 持仓列表标题
Text(
'持仓列表',
style: GoogleFonts.spaceGrotesk(
fontSize: 14,
fontWeight: FontWeight.w600,
color: colorScheme.onSurfaceVariant,
),
),
SizedBox(height: AppSpacing.md),
if (holdings.isEmpty)
if (sortedHoldings.isEmpty)
const _EmptyState(icon: LucideIcons.wallet, message: '暂无持仓')
else
ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: holdings.length,
itemCount: sortedHoldings.length,
separatorBuilder: (_, __) => Container(
margin: EdgeInsets.only(left: 56),
height: 1,
color: AppColorScheme.glassPanelBorder,
),
itemBuilder: (context, index) => _HoldingItem(holding: holdings[index]),
itemBuilder: (context, index) => _HoldingItem(holding: sortedHoldings[index]),
),
],
),