fix(ui): 修复主题切换功能,支持明暗主题动态切换
- 替换所有硬编码颜色为动态颜色 - 所有页面使用 Theme.of(context) 获取主题颜色 - 支持深色和浅色主题切换 - 修复 GlassPanel 和 NeonGlow 组件的主题适配 - 完善 lightMaterial ColorScheme 定义 - 测试主题切换功能正常 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@ import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/theme/app_color_scheme.dart';
|
||||
import '../../../providers/auth_provider.dart';
|
||||
import '../home/home_page.dart';
|
||||
import '../market/market_page.dart';
|
||||
@@ -48,8 +47,10 @@ class _MainPageState extends State<MainPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColorScheme.darkBackground,
|
||||
backgroundColor: colorScheme.background,
|
||||
body: Column(
|
||||
children: [
|
||||
// 公共顶部导航栏
|
||||
@@ -79,13 +80,16 @@ class _TopAppBar extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Container(
|
||||
height: 64,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorScheme.darkSurfaceBright.withValues(alpha: 0.4),
|
||||
color: colorScheme.surfaceBright.withOpacity(0.4),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColorScheme.darkPrimary.withValues(alpha: 0.06),
|
||||
color: colorScheme.primary.withOpacity(isDark ? 0.15 : 0.08),
|
||||
blurRadius: 64,
|
||||
offset: const Offset(0, 32),
|
||||
),
|
||||
@@ -111,15 +115,15 @@ class _TopAppBar extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.2),
|
||||
color: colorScheme.outlineVariant.withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
child: CircleAvatar(
|
||||
backgroundColor: AppColorScheme.darkSurfaceHigh,
|
||||
backgroundColor: colorScheme.surfaceContainerHigh,
|
||||
child: Text(
|
||||
auth.user?.avatarText ?? 'U',
|
||||
style: const TextStyle(
|
||||
color: AppColorScheme.darkPrimary,
|
||||
style: TextStyle(
|
||||
color: colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
@@ -128,10 +132,10 @@ class _TopAppBar extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 标题
|
||||
const Text(
|
||||
Text(
|
||||
'模拟所',
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkPrimary,
|
||||
color: colorScheme.primary,
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: -0.5,
|
||||
fontSize: 16,
|
||||
@@ -173,13 +177,15 @@ class _IconBtn extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: AppColorScheme.darkOnSurfaceVariant,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
@@ -201,18 +207,20 @@ class _BottomNavBar extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorScheme.darkSurfaceLow.withValues(alpha: 0.8),
|
||||
color: colorScheme.surfaceContainerLow.withOpacity(0.8),
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(32)),
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.15),
|
||||
color: colorScheme.outlineVariant.withOpacity(0.15),
|
||||
),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
blurRadius: 40,
|
||||
offset: const Offset(0, -10),
|
||||
),
|
||||
@@ -257,7 +265,8 @@ class _NavItemWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = isSelected ? AppColorScheme.darkPrimary : AppColorScheme.darkOnSurfaceVariant;
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final color = isSelected ? colorScheme.primary : colorScheme.onSurfaceVariant;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
@@ -267,11 +276,11 @@ class _NavItemWidget extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: isSelected
|
||||
? BoxDecoration(
|
||||
color: AppColorScheme.darkPrimary.withValues(alpha: 0.1),
|
||||
color: colorScheme.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColorScheme.darkPrimary.withValues(alpha: 0.3),
|
||||
color: colorScheme.primary.withOpacity(0.3),
|
||||
blurRadius: 15,
|
||||
spreadRadius: 0,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user