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

@@ -39,17 +39,19 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
@override
Widget build(BuildContext context) {
super.build(context);
final colorScheme = Theme.of(context).colorScheme;
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: AppColorScheme.darkBackground,
backgroundColor: colorScheme.background,
body: Consumer<MarketProvider>(
builder: (context, provider, _) {
return Column(
children: [
_buildSearchBar(provider),
_buildTabs(provider),
_buildSearchBar(provider, colorScheme),
_buildTabs(provider, colorScheme, isDark),
Expanded(
child: _buildCoinList(provider),
child: _buildCoinList(provider, colorScheme, isDark),
),
],
);
@@ -58,28 +60,28 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
);
}
Widget _buildSearchBar(MarketProvider provider) {
Widget _buildSearchBar(MarketProvider provider, ColorScheme colorScheme) {
return Padding(
padding: EdgeInsets.fromLTRB(AppSpacing.md, AppSpacing.md, AppSpacing.md, 0),
child: Container(
decoration: BoxDecoration(
color: AppColorScheme.darkSurfaceContainerLowest,
color: colorScheme.surfaceContainerLowest,
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.15),
color: colorScheme.outlineVariant.withOpacity(0.15),
),
),
child: TextField(
controller: _searchController,
onChanged: provider.search,
style: TextStyle(color: AppColorScheme.darkOnSurface),
style: TextStyle(color: colorScheme.onSurface),
decoration: InputDecoration(
hintText: '搜索市场...',
hintStyle: TextStyle(color: AppColorScheme.darkOnSurfaceVariant),
hintStyle: TextStyle(color: colorScheme.onSurfaceVariant),
prefixIcon: Icon(
LucideIcons.search,
size: 18,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
suffixIcon: _searchController.text.isNotEmpty
? GestureDetector(
@@ -90,7 +92,7 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
child: Icon(
LucideIcons.x,
size: 18,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
)
: null,
@@ -105,7 +107,7 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
);
}
Widget _buildTabs(MarketProvider provider) {
Widget _buildTabs(MarketProvider provider, ColorScheme colorScheme, bool isDark) {
final tabs = [
{'key': 'all', 'label': '全部'},
{'key': 'realtime', 'label': '实时'},
@@ -132,18 +134,18 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
),
decoration: BoxDecoration(
color: isActive
? AppColorScheme.darkPrimary.withValues(alpha: 0.1)
: AppColorScheme.darkSurfaceContainerHigh,
? colorScheme.primary.withOpacity(0.1)
: colorScheme.surfaceContainerHigh,
borderRadius: BorderRadius.circular(AppRadius.full),
border: isActive
? Border.all(
color: AppColorScheme.darkPrimary.withValues(alpha: 0.2),
color: colorScheme.primary.withOpacity(0.2),
)
: null,
boxShadow: isActive
? [
BoxShadow(
color: AppColorScheme.neonGlowPrimary,
color: colorScheme.primary.withOpacity(isDark ? 0.15 : 0.08),
blurRadius: 15,
),
]
@@ -153,8 +155,8 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
tab['label']!,
style: TextStyle(
color: isActive
? AppColorScheme.darkPrimary
: AppColorScheme.darkOnSurfaceVariant,
? colorScheme.primary
: colorScheme.onSurfaceVariant,
fontWeight: isActive ? FontWeight.w700 : FontWeight.normal,
fontSize: 12,
),
@@ -167,37 +169,37 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
);
}
Widget _buildCoinList(MarketProvider provider) {
Widget _buildCoinList(MarketProvider provider, ColorScheme colorScheme, bool isDark) {
if (provider.isLoading) {
return Center(
child: CircularProgressIndicator(
color: AppColorScheme.darkPrimary,
color: colorScheme.primary,
),
);
}
if (provider.error != null) {
return _buildErrorState(provider);
return _buildErrorState(provider, colorScheme);
}
final coins = provider.coins;
if (coins.isEmpty) {
return _buildEmptyState();
return _buildEmptyState(colorScheme);
}
return RefreshIndicator(
onRefresh: provider.refresh,
color: AppColorScheme.darkPrimary,
backgroundColor: AppColorScheme.darkSurfaceContainer,
color: colorScheme.primary,
backgroundColor: colorScheme.surfaceContainer,
child: ListView.builder(
padding: EdgeInsets.all(AppSpacing.md),
itemCount: coins.length,
itemBuilder: (context, index) => _buildCoinItem(coins[index]),
itemBuilder: (context, index) => _buildCoinItem(coins[index], colorScheme),
),
);
}
Widget _buildErrorState(MarketProvider provider) {
Widget _buildErrorState(MarketProvider provider, ColorScheme colorScheme) {
return Center(
child: Padding(
padding: AppSpacing.pagePadding,
@@ -207,12 +209,12 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
Icon(
LucideIcons.circleAlert,
size: 48,
color: AppColorScheme.darkError,
color: colorScheme.error,
),
SizedBox(height: AppSpacing.md),
Text(
provider.error!,
style: TextStyle(color: AppColorScheme.darkError),
style: TextStyle(color: colorScheme.error),
textAlign: TextAlign.center,
),
SizedBox(height: AppSpacing.lg),
@@ -226,7 +228,7 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
);
}
Widget _buildEmptyState() {
Widget _buildEmptyState(ColorScheme colorScheme) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
@@ -234,23 +236,23 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
Icon(
LucideIcons.coins,
size: 48,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
SizedBox(height: AppSpacing.md),
Text(
'暂无数据',
style: TextStyle(color: AppColorScheme.darkOnSurfaceVariant),
style: TextStyle(color: colorScheme.onSurfaceVariant),
),
],
),
);
}
Widget _buildCoinItem(Coin coin) {
Widget _buildCoinItem(Coin coin, ColorScheme colorScheme) {
final changeColor = coin.isUp ? AppColorScheme.up : AppColorScheme.down;
final changeBgColor = 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(
margin: EdgeInsets.only(bottom: AppSpacing.sm),
@@ -261,10 +263,10 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
width: 48,
height: 48,
decoration: BoxDecoration(
color: AppColorScheme.darkSurfaceContainerHighest,
color: colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.2),
color: colorScheme.outlineVariant.withOpacity(0.2),
),
),
child: Center(
@@ -272,7 +274,7 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
coin.displayIcon,
style: TextStyle(
fontSize: 20,
color: coin.isUp ? AppColorScheme.darkPrimary : AppColorScheme.darkSecondary,
color: coin.isUp ? colorScheme.primary : colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
@@ -291,7 +293,7 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
style: GoogleFonts.spaceGrotesk(
fontSize: 16,
fontWeight: FontWeight.bold,
color: AppColorScheme.darkOnSurface,
color: colorScheme.onSurface,
),
),
SizedBox(width: AppSpacing.xs),
@@ -299,7 +301,7 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
'/USDT',
style: TextStyle(
fontSize: 12,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
),
],
@@ -309,7 +311,7 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
coin.name,
style: TextStyle(
fontSize: 12,
color: AppColorScheme.darkOnSurfaceVariant,
color: colorScheme.onSurfaceVariant,
),
),
],
@@ -324,7 +326,7 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
style: GoogleFonts.spaceGrotesk(
fontSize: 14,
fontWeight: FontWeight.bold,
color: AppColorScheme.darkOnSurface,
color: colorScheme.onSurface,
),
),
SizedBox(height: AppSpacing.xs),
@@ -337,7 +339,7 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
color: changeBgColor,
borderRadius: BorderRadius.circular(AppRadius.sm),
border: Border.all(
color: changeColor.withValues(alpha: 0.2),
color: changeColor.withOpacity(0.2),
),
),
child: Text(