feat: implement base architecture and core repositories for weapon tracking and target analysis functionality
This commit is contained in:
44
lib/core/theme/theme_provider.dart
Normal file
44
lib/core/theme/theme_provider.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class ThemeProvider with ChangeNotifier {
|
||||
static const String _themeModeKey = 'user_theme_mode';
|
||||
|
||||
ThemeMode _themeMode = ThemeMode.system;
|
||||
|
||||
ThemeMode get themeMode => _themeMode;
|
||||
|
||||
ThemeProvider() {
|
||||
loadThemeMode();
|
||||
}
|
||||
|
||||
Future<void> loadThemeMode() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final modeIndex = prefs.getInt(_themeModeKey);
|
||||
if (modeIndex != null) {
|
||||
_themeMode = ThemeMode.values[modeIndex];
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setThemeMode(ThemeMode mode) async {
|
||||
if (_themeMode == mode) return;
|
||||
|
||||
_themeMode = mode;
|
||||
notifyListeners();
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(_themeModeKey, mode.index);
|
||||
}
|
||||
|
||||
String get themeModeName {
|
||||
switch (_themeMode) {
|
||||
case ThemeMode.system:
|
||||
return 'Automatique';
|
||||
case ThemeMode.light:
|
||||
return 'Clair';
|
||||
case ThemeMode.dark:
|
||||
return 'Sombre';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user