- 创建 AppThemeColors ThemeExtension 类,统一管理主题感知颜色(涨跌色、卡片背景、渐变等) - 从 AppColorScheme 移除主题感知辅助函数,仅保留静态颜色常量 - 在 AppTheme 中注册 ThemeExtension,支持深色/浅色主题工厂 - 重构所有 UI 组件使用 context.appColors 访问主题颜色,替代硬编码的 AppColorScheme 方法调用 - 移除组件中重复的 isDark 判断逻辑,简化颜色获取方式 - 保持向后兼容性,所有现有功能不变
76 lines
2.3 KiB
Dart
76 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../../core/theme/app_theme.dart';
|
|
import '../../../../core/theme/app_theme_extension.dart';
|
|
import '../../../../core/theme/app_spacing.dart';
|
|
import '../../../../providers/asset_provider.dart';
|
|
import '../../../components/glass_panel.dart';
|
|
|
|
/// 余额卡片 — .pen node 59637
|
|
/// cornerRadius: lg, fill: $surface-card, padding: 20, stroke: $border-default 1px, gap: 12
|
|
/// balLabel: "USDT 余额" 12px normal $text-secondary
|
|
/// balAmount: "25,680.50" 28px w700 $text-primary
|
|
/// balSubRow: "≈ $25,680.50 USD" 12px normal $text-muted
|
|
class BalanceCard extends StatelessWidget {
|
|
final AssetProvider provider;
|
|
final int activeTab;
|
|
|
|
const BalanceCard({
|
|
super.key,
|
|
required this.provider,
|
|
required this.activeTab,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final displayBalance = activeTab == 0
|
|
? (provider.fundAccount?.balance ?? provider.overview?.fundBalance ?? '0.00')
|
|
: _calculateTradeTotal();
|
|
|
|
return GlassPanel(
|
|
padding: const EdgeInsets.all(20),
|
|
borderRadius: BorderRadius.circular(AppRadius.lg),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'USDT 余额',
|
|
style: AppTextStyles.bodyMedium(context).copyWith(
|
|
color: context.colors.onSurfaceVariant,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
_formatBalance(displayBalance),
|
|
style: AppTextStyles.numberLarge(context),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
'\u2248 \$${_formatBalance(displayBalance)} USD',
|
|
style: AppTextStyles.bodyMedium(context).copyWith(
|
|
color: context.appColors.onSurfaceMuted,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
String _calculateTradeTotal() {
|
|
double total = 0;
|
|
for (var h in provider.holdings) {
|
|
total += double.tryParse(h.currentValue?.toString() ?? '0') ?? 0;
|
|
}
|
|
return total.toStringAsFixed(2);
|
|
}
|
|
|
|
String _formatBalance(String balance) {
|
|
final d = double.tryParse(balance) ?? 0;
|
|
return d.toStringAsFixed(2).replaceAllMapped(
|
|
RegExp(r'\B(?=(\d{3})+(?!\d))'),
|
|
(Match m) => ',',
|
|
);
|
|
}
|
|
}
|