refactor(theme): 迁移主题感知颜色至 ThemeExtension
- 创建 AppThemeColors ThemeExtension 类,统一管理主题感知颜色(涨跌色、卡片背景、渐变等) - 从 AppColorScheme 移除主题感知辅助函数,仅保留静态颜色常量 - 在 AppTheme 中注册 ThemeExtension,支持深色/浅色主题工厂 - 重构所有 UI 组件使用 context.appColors 访问主题颜色,替代硬编码的 AppColorScheme 方法调用 - 移除组件中重复的 isDark 判断逻辑,简化颜色获取方式 - 保持向后兼容性,所有现有功能不变
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../core/theme/app_color_scheme.dart';
|
||||
import '../../core/theme/app_spacing.dart';
|
||||
import '../../core/theme/app_theme_extension.dart';
|
||||
|
||||
/// NeonGlow - 霓虹光效组件
|
||||
///
|
||||
@@ -94,7 +95,7 @@ class NeonGlow extends StatelessWidget {
|
||||
}) {
|
||||
return NeonGlow(
|
||||
key: key,
|
||||
glowColor: AppColorScheme.down.withOpacity(0.3),
|
||||
glowColor: AppColorScheme.down.withValues(alpha: 0.3),
|
||||
blurRadius: blurRadius,
|
||||
borderRadius: borderRadius,
|
||||
child: child,
|
||||
@@ -205,16 +206,15 @@ class _NeonButtonState extends State<NeonButton>
|
||||
}
|
||||
|
||||
Color get _backgroundColor {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final colors = context.colors;
|
||||
|
||||
switch (widget.type) {
|
||||
case NeonButtonType.primary:
|
||||
return colorScheme.primary;
|
||||
return colors.primary;
|
||||
case NeonButtonType.secondary:
|
||||
return colorScheme.secondary;
|
||||
return colors.secondary;
|
||||
case NeonButtonType.tertiary:
|
||||
return AppColorScheme.getUpColor(isDark);
|
||||
return context.appColors.up;
|
||||
case NeonButtonType.error:
|
||||
return AppColorScheme.down;
|
||||
case NeonButtonType.outline:
|
||||
@@ -223,38 +223,37 @@ class _NeonButtonState extends State<NeonButton>
|
||||
}
|
||||
|
||||
Color get _foregroundColor {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final colors = context.colors;
|
||||
|
||||
switch (widget.type) {
|
||||
case NeonButtonType.primary:
|
||||
return isDark ? AppColorScheme.darkOnPrimary : const Color(0xFFFFFFFF);
|
||||
return colors.onPrimary;
|
||||
case NeonButtonType.secondary:
|
||||
return isDark ? AppColorScheme.darkOnSecondary : const Color(0xFFFFFFFF);
|
||||
return colors.onSecondary;
|
||||
case NeonButtonType.tertiary:
|
||||
return isDark ? AppColorScheme.darkOnTertiary : const Color(0xFFFFFFFF);
|
||||
return colors.onTertiary;
|
||||
case NeonButtonType.error:
|
||||
return const Color(0xFFFFFFFF);
|
||||
case NeonButtonType.outline:
|
||||
return colorScheme.primary;
|
||||
return colors.primary;
|
||||
}
|
||||
}
|
||||
|
||||
Color get _glowColor {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final colors = context.colors;
|
||||
final appColors = context.appColors;
|
||||
|
||||
switch (widget.type) {
|
||||
case NeonButtonType.primary:
|
||||
return colorScheme.primary.withOpacity(isDark ? 0.15 : 0.08);
|
||||
return colors.primary.withValues(alpha: appColors.glowOpacity);
|
||||
case NeonButtonType.secondary:
|
||||
return colorScheme.secondary.withOpacity(isDark ? 0.15 : 0.08);
|
||||
return colors.secondary.withValues(alpha: appColors.glowOpacity);
|
||||
case NeonButtonType.tertiary:
|
||||
return AppColorScheme.getUpBackgroundColor(isDark, opacity: isDark ? 0.2 : 0.1);
|
||||
return context.appColors.upBackground;
|
||||
case NeonButtonType.error:
|
||||
return AppColorScheme.down.withOpacity(0.3);
|
||||
return AppColorScheme.down.withValues(alpha: 0.3);
|
||||
case NeonButtonType.outline:
|
||||
return colorScheme.primary.withOpacity(isDark ? 0.15 : 0.08);
|
||||
return colors.primary.withValues(alpha: appColors.glowOpacity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,8 +264,7 @@ class _NeonButtonState extends State<NeonButton>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final colors = context.colors;
|
||||
|
||||
final button = GestureDetector(
|
||||
onTapDown: widget.onPressed != null ? _onTapDown : null,
|
||||
@@ -286,7 +284,7 @@ class _NeonButtonState extends State<NeonButton>
|
||||
),
|
||||
border: widget.type == NeonButtonType.outline
|
||||
? Border.all(
|
||||
color: colorScheme.outlineVariant.withOpacity(0.3),
|
||||
color: colors.outlineVariant.withValues(alpha: 0.3),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user