165 lines
5.3 KiB
Dart
165 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
@immutable
|
|
class AppColors extends ThemeExtension<AppColors> {
|
|
final Color background; // 页面背景
|
|
final Color surface; // 卡片/面板背景
|
|
final Color textPrimary; // 主文字
|
|
final Color textSecondary; // 次要文字
|
|
final Color textTertiary; // 弱化文字
|
|
final Color divider; // 分割线
|
|
final Color icon; // 图标色
|
|
|
|
final Color healthGreen; // 健康度 ≥80%
|
|
final Color healthYellow; // 70~80%
|
|
final Color healthOrange;
|
|
final Color healthRed; // <70% 或异常
|
|
final Color barEmpty; // 无数据柱
|
|
|
|
final Color voltUp; // 电压↑
|
|
final Color voltDown; // 电压↓
|
|
final Color tempUp;
|
|
final Color tempDown;
|
|
|
|
final Color progressBar; // 更新日志进度条
|
|
final Color statusBarTint; // 状态栏背景
|
|
|
|
const AppColors({
|
|
required this.background,
|
|
required this.surface,
|
|
required this.textPrimary,
|
|
required this.textSecondary,
|
|
required this.textTertiary,
|
|
required this.divider,
|
|
required this.icon,
|
|
required this.healthGreen,
|
|
required this.healthYellow,
|
|
required this.healthOrange,
|
|
required this.healthRed,
|
|
required this.barEmpty,
|
|
required this.voltUp,
|
|
required this.voltDown,
|
|
required this.tempUp,
|
|
required this.tempDown,
|
|
required this.progressBar,
|
|
required this.statusBarTint,
|
|
});
|
|
|
|
@override
|
|
AppColors copyWith({
|
|
Color? background,
|
|
Color? surface,
|
|
Color? textPrimary,
|
|
Color? textSecondary,
|
|
Color? textTertiary,
|
|
Color? divider,
|
|
Color? icon,
|
|
Color? healthGreen,
|
|
Color? healthYellow,
|
|
Color? healthOrange,
|
|
Color? healthRed,
|
|
Color? barEmpty,
|
|
Color? voltUp,
|
|
Color? voltDown,
|
|
Color? tempUp,
|
|
Color? tempDown,
|
|
Color? progressBar,
|
|
Color? statusBarTint,
|
|
}) {
|
|
return AppColors(
|
|
background: background ?? this.background,
|
|
surface: surface ?? this.surface,
|
|
textPrimary: textPrimary ?? this.textPrimary,
|
|
textSecondary: textSecondary ?? this.textSecondary,
|
|
textTertiary: textTertiary ?? this.textTertiary,
|
|
divider: divider ?? this.divider,
|
|
icon: icon ?? this.icon,
|
|
healthGreen: healthGreen ?? this.healthGreen,
|
|
healthYellow: healthYellow ?? this.healthYellow,
|
|
healthOrange: healthOrange ?? this.healthOrange,
|
|
healthRed: healthRed ?? this.healthRed,
|
|
barEmpty: barEmpty ?? this.barEmpty,
|
|
voltUp: voltUp ?? this.voltUp,
|
|
voltDown: voltDown ?? this.voltDown,
|
|
tempUp: tempUp ?? this.tempUp,
|
|
tempDown: tempDown ?? this.tempDown,
|
|
progressBar: progressBar ?? this.progressBar,
|
|
statusBarTint: statusBarTint ?? this.statusBarTint,
|
|
);
|
|
}
|
|
|
|
@override
|
|
AppColors lerp(ThemeExtension<AppColors>? other, double t) {
|
|
if (other is! AppColors) return this;
|
|
return AppColors(
|
|
background: Color.lerp(background, other.background, t)!,
|
|
surface: Color.lerp(surface, other.surface, t)!,
|
|
textPrimary: Color.lerp(textPrimary, other.textPrimary, t)!,
|
|
textSecondary: Color.lerp(textSecondary, other.textSecondary, t)!,
|
|
textTertiary: Color.lerp(textTertiary, other.textTertiary, t)!,
|
|
divider: Color.lerp(divider, other.divider, t)!,
|
|
icon: Color.lerp(icon, other.icon, t)!,
|
|
healthGreen: Color.lerp(healthGreen, other.healthGreen, t)!,
|
|
healthYellow: Color.lerp(healthYellow, other.healthYellow, t)!,
|
|
healthOrange: Color.lerp(healthOrange, other.healthOrange, t)!,
|
|
healthRed: Color.lerp(healthRed, other.healthRed, t)!,
|
|
barEmpty: Color.lerp(barEmpty, other.barEmpty, t)!,
|
|
voltUp: Color.lerp(voltUp, other.voltUp, t)!,
|
|
voltDown: Color.lerp(voltDown, other.voltDown, t)!,
|
|
tempUp: Color.lerp(tempUp, other.tempUp, t)!,
|
|
tempDown: Color.lerp(tempDown, other.tempDown, t)!,
|
|
progressBar: Color.lerp(progressBar, other.progressBar, t)!,
|
|
statusBarTint: Color.lerp(statusBarTint, other.statusBarTint, t)!,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 浅色主题(保持现有视觉)
|
|
const AppColors kLightColors = AppColors(
|
|
background: Colors.white,
|
|
surface: Color(0xFFF0F4F8),
|
|
textPrimary: Colors.black,
|
|
textSecondary: Color(0xFF5F5F5F),
|
|
textTertiary: Colors.grey,
|
|
divider: Color(0xFFE0E0E0),
|
|
icon: Colors.black,
|
|
healthGreen: Color(0xFF00B140),
|
|
healthYellow: Color(0xFFEFDF00),
|
|
healthOrange: Color(0xFFD75A16),
|
|
healthRed: Colors.red,
|
|
barEmpty: Color(0xFFE0E0E0),
|
|
voltUp: Colors.red,
|
|
voltDown: Colors.blue,
|
|
tempUp: Colors.red,
|
|
tempDown: Colors.blue,
|
|
progressBar: Color.fromRGBO(157, 212, 237, 1.0),
|
|
statusBarTint: Color.fromRGBO(157, 212, 237, 0.1),
|
|
);
|
|
|
|
/// 深色主题(色相保留,明度调整)
|
|
const AppColors kDarkColors = AppColors(
|
|
background: Color(0xFF121212),
|
|
surface: Color(0xFF1E1E1E),
|
|
textPrimary: Color(0xFFE8E8E8),
|
|
textSecondary: Color(0xFFA0A0A0),
|
|
textTertiary: Color(0xFF707070),
|
|
divider: Color(0xFF2A2A2A),
|
|
icon: Color(0xFFE8E8E8),
|
|
healthGreen: Color(0xFF00D14D),
|
|
healthYellow: Color(0xFFD4C520),
|
|
healthOrange: Color(0xFFFF7838),
|
|
healthRed: Color(0xFFFF5252),
|
|
barEmpty: Color(0xFF2A2A2A),
|
|
voltUp: Color(0xFFFF5252),
|
|
voltDown: Color(0xFF5AA9FF),
|
|
tempUp: Color(0xFFFF5252),
|
|
tempDown: Color(0xFF5AA9FF),
|
|
progressBar: Color(0xFF5A9BBD),
|
|
statusBarTint: Color(0xFF121212),
|
|
);
|
|
|
|
/// 便捷扩展:context.colors.textPrimary
|
|
extension AppColorsX on BuildContext {
|
|
AppColors get colors => Theme.of(this).extension<AppColors>()!;
|
|
}
|