前端改动: - 新建设置页面 (主题切换/关于/隐私政策/用户协议/儿童隐私保护) - SettingsBloc 注册到 MultiRepositoryProvider 全局可访问 - MoodBloc 修复编译错误 + 接入 /diary/stats/mood API - MoodPage 添加错误状态展示和重试按钮 - AchievementBloc + 页面改造接入 /diary/achievements API - StickerBloc + 页面改造接入 /diary/sticker-packs API - TemplateBloc + 页面改造接入 /diary/templates API - ProfilePage 设置入口改为跳转 /settings - 添加 /settings 路由 后端改动: - 扩展 mood_stats_service 测试 (连续天数算法/心情计数/边界场景) - 新增 class_service 测试 (班级码生成/唯一性/错误映射) - 新增 achievement_service 测试 (DTO 结构/序列化/map 构建) - 新增 sticker_service 测试 (DTO 序列化/错误处理) - 扩展 dto.rs 测试 (achievement/mood_stats/sticker/template/notification) - 清理 2 个 unused import warning 验证: - cargo check 0 error 0 warning - flutter analyze 0 error
51 lines
1.3 KiB
Dart
51 lines
1.3 KiB
Dart
// 设置 BLoC — 主题切换 + 应用设置管理
|
||
//
|
||
// ChangeNotifier 模式(同 MoodBloc),通过 ListenableBuilder 消费。
|
||
// Phase 1: 内存态 + TODO 持久化到 SharedPreferences。
|
||
|
||
import 'package:flutter/material.dart';
|
||
|
||
// ===== State =====
|
||
|
||
/// 设置页面状态
|
||
class SettingsState {
|
||
final ThemeMode themeMode;
|
||
final bool isLoading;
|
||
|
||
const SettingsState({
|
||
this.themeMode = ThemeMode.system,
|
||
this.isLoading = false,
|
||
});
|
||
|
||
SettingsState copyWith({ThemeMode? themeMode, bool? isLoading}) =>
|
||
SettingsState(
|
||
themeMode: themeMode ?? this.themeMode,
|
||
isLoading: isLoading ?? this.isLoading,
|
||
);
|
||
}
|
||
|
||
// ===== BLoC =====
|
||
|
||
/// 设置管理器 — 全局单例,在 NuanjiApp 中创建
|
||
class SettingsBloc extends ChangeNotifier {
|
||
SettingsState _state = const SettingsState();
|
||
SettingsState get state => _state;
|
||
|
||
/// 切换主题模式
|
||
void changeTheme(ThemeMode mode) {
|
||
_state = _state.copyWith(themeMode: mode);
|
||
notifyListeners();
|
||
// TODO: 持久化到 SharedPreferences
|
||
}
|
||
|
||
/// 循环切换: system → light → dark → system
|
||
void cycleTheme() {
|
||
final next = switch (_state.themeMode) {
|
||
ThemeMode.system => ThemeMode.light,
|
||
ThemeMode.light => ThemeMode.dark,
|
||
ThemeMode.dark => ThemeMode.system,
|
||
};
|
||
changeTheme(next);
|
||
}
|
||
}
|