|
|
|
|
@ -1,14 +1,32 @@
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/cache_service.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/theme/colors.dart';
|
|
|
|
|
|
|
|
|
|
class ProfileSettingsViewModel extends ChangeNotifier {
|
|
|
|
|
static const String _darkModeKey = 'is_dark_mode';
|
|
|
|
|
|
|
|
|
|
final CacheService _cacheService;
|
|
|
|
|
|
|
|
|
|
bool _isDarkMode = false;
|
|
|
|
|
|
|
|
|
|
bool get isDarkMode => _isDarkMode;
|
|
|
|
|
|
|
|
|
|
ProfileSettingsViewModel({required CacheService cacheService})
|
|
|
|
|
: _cacheService = cacheService;
|
|
|
|
|
|
|
|
|
|
/// Call once at app startup (before the first frame) to restore the
|
|
|
|
|
/// persisted dark-mode preference.
|
|
|
|
|
void loadDarkMode() {
|
|
|
|
|
final saved = _cacheService.getBool(key: _darkModeKey);
|
|
|
|
|
_isDarkMode = saved ?? false;
|
|
|
|
|
AppColors.isDarkMode = _isDarkMode;
|
|
|
|
|
// No notifyListeners() here — we are called before build.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void toggleDarkMode(bool value) {
|
|
|
|
|
_isDarkMode = value;
|
|
|
|
|
AppColors.isDarkMode = value;
|
|
|
|
|
_cacheService.saveBool(key: _darkModeKey, value: value);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|