// 设置 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); } }