fix(ui): 修复主题切换功能,支持明暗主题动态切换

- 替换所有硬编码颜色为动态颜色
- 所有页面使用 Theme.of(context) 获取主题颜色
- 支持深色和浅色主题切换
- 修复 GlassPanel 和 NeonGlow 组件的主题适配
- 完善 lightMaterial ColorScheme 定义
- 测试主题切换功能正常

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-24 02:50:25 +08:00
parent 7bb426b3d8
commit a65aa0fa86
94 changed files with 17889 additions and 17478 deletions

View File

@@ -49,9 +49,10 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
@override
Widget build(BuildContext context) {
super.build(context);
final colorScheme = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: AppColorScheme.darkBackground,
backgroundColor: colorScheme.background,
body: Consumer2<MarketProvider, AssetProvider>(
builder: (context, market, asset, _) {
return SingleChildScrollView(
@@ -99,6 +100,7 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
}
void _executeTrade() {
final colorScheme = Theme.of(context).colorScheme;
final price = _priceController.text;
final quantity = _quantityController.text;
final isBuy = _tradeType == 0;
@@ -123,6 +125,7 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
}
void _showTradeResult() {
final colorScheme = Theme.of(context).colorScheme;
final isBuy = _tradeType == 0;
showShadDialog(
@@ -132,7 +135,7 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
children: [
NeonIcon(
icon: Icons.check_circle,
color: AppColorScheme.darkPrimary,
color: colorScheme.primary,
size: 24,
),
SizedBox(width: AppSpacing.sm),
@@ -168,6 +171,8 @@ class _CoinSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
// 自动选择第一个币种
if (selectedCoin == null && coins.isNotEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) => onCoinLoaded(coins.first));
@@ -188,7 +193,7 @@ class _CoinSelector extends StatelessWidget {
style: GoogleFonts.spaceGrotesk(
fontSize: 18,
fontWeight: FontWeight.bold,
color: AppColorScheme.darkOnSurface,
color: colorScheme.onSurface,
),
),
SizedBox(height: AppSpacing.xs),
@@ -196,7 +201,7 @@ class _CoinSelector extends StatelessWidget {
selectedCoin?.name ?? '点击选择交易对',
style: TextStyle(
fontSize: 12,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
),
],
@@ -204,7 +209,7 @@ class _CoinSelector extends StatelessWidget {
),
Icon(
LucideIcons.chevronRight,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
],
),
@@ -220,14 +225,16 @@ class _CoinAvatar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: AppColorScheme.darkPrimary.withValues(alpha: 0.1),
color: colorScheme.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(
color: AppColorScheme.darkPrimary.withValues(alpha: 0.2),
color: colorScheme.primary.withOpacity(0.2),
),
),
child: Center(
@@ -235,7 +242,7 @@ class _CoinAvatar extends StatelessWidget {
icon ?? '?',
style: TextStyle(
fontSize: 20,
color: AppColorScheme.darkPrimary,
color: colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
@@ -252,10 +259,11 @@ class _PriceCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final color = coin.isUp ? AppColorScheme.up : AppColorScheme.down;
final bgColor = coin.isUp
? AppColorScheme.darkTertiary.withValues(alpha: 0.1)
: AppColorScheme.darkError.withValues(alpha: 0.1);
? AppColorScheme.up.withOpacity(0.1)
: colorScheme.error.withOpacity(0.1);
return GlassCard(
showNeonGlow: false,
@@ -269,7 +277,7 @@ class _PriceCard extends StatelessWidget {
'最新价',
style: TextStyle(
fontSize: 12,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
),
SizedBox(height: AppSpacing.xs),
@@ -278,7 +286,7 @@ class _PriceCard extends StatelessWidget {
style: GoogleFonts.spaceGrotesk(
fontSize: 28,
fontWeight: FontWeight.bold,
color: AppColorScheme.darkOnSurface,
color: colorScheme.onSurface,
),
),
],
@@ -292,7 +300,7 @@ class _PriceCard extends StatelessWidget {
color: bgColor,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(
color: color.withValues(alpha: 0.2),
color: color.withOpacity(0.2),
),
),
child: Text(
@@ -330,6 +338,8 @@ class _TradeForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return GlassPanel(
padding: EdgeInsets.all(AppSpacing.lg),
child: Column(
@@ -346,6 +356,7 @@ class _TradeForm extends StatelessWidget {
controller: priceController,
placeholder: '输入价格',
suffix: 'USDT',
colorScheme: colorScheme,
),
SizedBox(height: AppSpacing.md),
// 数量输入
@@ -354,12 +365,13 @@ class _TradeForm extends StatelessWidget {
controller: quantityController,
placeholder: '输入数量',
suffix: selectedCoin?.code ?? '',
colorScheme: colorScheme,
),
SizedBox(height: AppSpacing.lg),
// 信息行
_InfoRow(label: '交易金额', value: '${_calculateAmount()} USDT'),
_InfoRow(label: '交易金额', value: '${_calculateAmount()} USDT', colorScheme: colorScheme),
SizedBox(height: AppSpacing.sm),
_InfoRow(label: '可用', value: '${tradeBalance ?? '0.00'} USDT'),
_InfoRow(label: '可用', value: '${tradeBalance ?? '0.00'} USDT', colorScheme: colorScheme),
],
),
);
@@ -370,6 +382,7 @@ class _TradeForm extends StatelessWidget {
required TextEditingController controller,
required String placeholder,
required String suffix,
required ColorScheme colorScheme,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -380,16 +393,16 @@ class _TradeForm extends StatelessWidget {
fontSize: 10,
fontWeight: FontWeight.w700,
letterSpacing: 0.2,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
),
SizedBox(height: AppSpacing.xs),
Container(
decoration: BoxDecoration(
color: AppColorScheme.darkSurfaceLowest,
color: colorScheme.surfaceContainerLowest,
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.3),
color: colorScheme.outlineVariant.withOpacity(0.3),
),
),
child: TextField(
@@ -398,12 +411,12 @@ class _TradeForm extends StatelessWidget {
style: GoogleFonts.spaceGrotesk(
fontSize: 20,
fontWeight: FontWeight.bold,
color: AppColorScheme.darkOnSurface,
color: colorScheme.onSurface,
),
decoration: InputDecoration(
hintText: placeholder,
hintStyle: TextStyle(
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.5),
color: colorScheme.outlineVariant.withOpacity(0.5),
),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
@@ -417,7 +430,7 @@ class _TradeForm extends StatelessWidget {
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
),
),
@@ -445,10 +458,12 @@ class _TradeTypeSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return Container(
padding: EdgeInsets.all(AppSpacing.xs),
decoration: BoxDecoration(
color: AppColorScheme.darkSurfaceLowest,
color: colorScheme.surfaceContainerLowest,
borderRadius: BorderRadius.circular(AppRadius.xl),
),
child: Row(
@@ -498,15 +513,15 @@ class _TypeButton extends StatelessWidget {
duration: const Duration(milliseconds: 200),
padding: EdgeInsets.symmetric(vertical: AppSpacing.sm + AppSpacing.xs),
decoration: BoxDecoration(
color: isSelected ? color.withValues(alpha: 0.15) : Colors.transparent,
color: isSelected ? color.withOpacity(0.15) : Colors.transparent,
borderRadius: BorderRadius.circular(AppRadius.md),
border: isSelected ? null : Border.all(color: color.withValues(alpha: 0.3)),
border: isSelected ? null : Border.all(color: color.withOpacity(0.3)),
),
child: Center(
child: Text(
label,
style: TextStyle(
color: isSelected ? color : color.withValues(alpha: 0.7),
color: isSelected ? color : color.withOpacity(0.7),
fontWeight: FontWeight.w700,
fontSize: 14,
letterSpacing: 0.5,
@@ -522,8 +537,9 @@ class _TypeButton extends StatelessWidget {
class _InfoRow extends StatelessWidget {
final String label;
final String value;
final ColorScheme colorScheme;
const _InfoRow({required this.label, required this.value});
const _InfoRow({required this.label, required this.value, required this.colorScheme});
@override
Widget build(BuildContext context) {
@@ -534,7 +550,7 @@ class _InfoRow extends StatelessWidget {
label,
style: TextStyle(
fontSize: 14,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
),
Text(
@@ -542,7 +558,7 @@ class _InfoRow extends StatelessWidget {
style: GoogleFonts.spaceGrotesk(
fontSize: 14,
fontWeight: FontWeight.w600,
color: AppColorScheme.darkOnSurface,
color: colorScheme.onSurface,
),
),
],