refactor(theme): 迁移主题感知颜色至 ThemeExtension
- 创建 AppThemeColors ThemeExtension 类,统一管理主题感知颜色(涨跌色、卡片背景、渐变等) - 从 AppColorScheme 移除主题感知辅助函数,仅保留静态颜色常量 - 在 AppTheme 中注册 ThemeExtension,支持深色/浅色主题工厂 - 重构所有 UI 组件使用 context.appColors 访问主题颜色,替代硬编码的 AppColorScheme 方法调用 - 移除组件中重复的 isDark 判断逻辑,简化颜色获取方式 - 保持向后兼容性,所有现有功能不变
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import '../../../core/theme/app_color_scheme.dart';
|
||||
import '../../../core/theme/app_spacing.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/theme/app_theme_extension.dart';
|
||||
import '../../../core/storage/local_storage.dart';
|
||||
|
||||
/// 引导页数据模型
|
||||
@@ -91,11 +92,8 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: colorScheme.surface,
|
||||
backgroundColor: context.colors.surface,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -113,7 +111,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
child: Text(
|
||||
'跳过',
|
||||
style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
color: context.colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -131,7 +129,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
},
|
||||
itemCount: _items.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _buildPage(_items[index], isDark);
|
||||
return _buildPage(_items[index]);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -150,7 +148,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(
|
||||
_items.length,
|
||||
(index) => _buildIndicator(index, isDark),
|
||||
(index) => _buildIndicator(index),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
@@ -161,8 +159,8 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
child: ElevatedButton(
|
||||
onPressed: _nextPage,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: colorScheme.primary,
|
||||
foregroundColor: colorScheme.onPrimary,
|
||||
backgroundColor: context.colors.primary,
|
||||
foregroundColor: context.colors.onPrimary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
),
|
||||
@@ -185,9 +183,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPage(_OnboardingItem item, bool isDark) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
Widget _buildPage(_OnboardingItem item) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xl),
|
||||
child: Column(
|
||||
@@ -225,7 +221,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
return Icon(
|
||||
item.icon ?? LucideIcons.image,
|
||||
size: 72,
|
||||
color: AppColorScheme.darkOnPrimary,
|
||||
color: context.colors.onPrimary,
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -233,7 +229,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
: Icon(
|
||||
item.icon ?? LucideIcons.star,
|
||||
size: 72,
|
||||
color: AppColorScheme.darkOnPrimary,
|
||||
color: context.colors.onPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -243,7 +239,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
item.title,
|
||||
style: AppTextStyles.displaySmall(context).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: colorScheme.onSurface,
|
||||
color: context.colors.onSurface,
|
||||
letterSpacing: -0.5,
|
||||
),
|
||||
),
|
||||
@@ -253,7 +249,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
item.description,
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
color: context.colors.onSurfaceVariant,
|
||||
height: 1.6,
|
||||
),
|
||||
),
|
||||
@@ -262,8 +258,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIndicator(int index, bool isDark) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
Widget _buildIndicator(int index) {
|
||||
final isActive = index == _currentPage;
|
||||
|
||||
return AnimatedContainer(
|
||||
@@ -272,7 +267,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
width: isActive ? 24 : 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? colorScheme.primary : colorScheme.outlineVariant,
|
||||
color: isActive ? context.colors.primary : context.colors.outlineVariant,
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user