关怀模式

This commit is contained in:
Developer
2026-04-02 22:30:49 +08:00
parent 09fee0694c
commit 7872f2e78a
70 changed files with 4884 additions and 2752 deletions

View File

@@ -5,6 +5,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../models/colors/theme_colors.dart';
import '../../models/night-mode/theme_model.dart';
/// 主题控制器
@@ -40,6 +41,14 @@ class ThemeController extends GetxController {
bool get enableAnimation => _enableAnimation.value;
bool get enableBlurEffect => _enableBlurEffect.value;
// 获取当前主题颜色
Color get currentThemeColor =>
ThemeColors.getThemeColor(_themeColorIndex.value);
// 获取当前强调色
Color get currentAccentColor =>
ThemeColors.getAccentColor(_accentColorIndex.value);
/// 获取当前 Flutter ThemeMode
ThemeMode get currentThemeMode {
if (_isDarkMode.value) {
@@ -71,9 +80,11 @@ class ThemeController extends GetxController {
_prefs = await SharedPreferences.getInstance();
_isDarkMode.value = _prefs?.getBool(_darkModeKey) ?? false;
_themeMode.value = AppThemeMode.values[
(_prefs?.getInt(_themeModeKey) ?? 0).clamp(0, AppThemeMode.values.length - 1)
];
_themeMode.value =
AppThemeMode.values[(_prefs?.getInt(_themeModeKey) ?? 0).clamp(
0,
AppThemeMode.values.length - 1,
)];
_themeColorIndex.value = _prefs?.getInt(_themeColorIndexKey) ?? 0;
_accentColorIndex.value = _prefs?.getInt(_accentColorIndexKey) ?? 0;
_fontSizeIndex.value = _prefs?.getInt(_fontSizeIndexKey) ?? 1;
@@ -102,6 +113,14 @@ class ThemeController extends GetxController {
Get.changeThemeMode(currentThemeMode);
}
/// 应用主题颜色到 GetX
void _applyThemeColor() {
// 这里可以根据需要创建新的主题并应用
// 由于我们使用的是 GetX 的主题系统,
// 我们可以通过更新全局状态来让组件响应主题颜色变化
update();
}
/// 切换深色模式
/// [enabled] true 开启深色模式, false 关闭深色模式
Future<void> toggleDarkMode(bool enabled) async {
@@ -144,6 +163,17 @@ class ThemeController extends GetxController {
_themeColorIndex.value = index;
await _saveThemeSettings();
_applyThemeColor();
// 显示提示
Get.snackbar(
'主题颜色',
'已更换主题颜色',
snackPosition: SnackPosition.BOTTOM,
duration: const Duration(seconds: 2),
margin: const EdgeInsets.all(16),
borderRadius: 12,
);
}
/// 设置强调色索引
@@ -152,6 +182,17 @@ class ThemeController extends GetxController {
_accentColorIndex.value = index;
await _saveThemeSettings();
_applyThemeColor();
// 显示提示
Get.snackbar(
'强调颜色',
'已更换强调颜色',
snackPosition: SnackPosition.BOTTOM,
duration: const Duration(seconds: 2),
margin: const EdgeInsets.all(16),
borderRadius: 12,
);
}
/// 设置字体大小索引