mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
#687 enhancement theme-customization
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
- sizzlesloth - <https://github.com/sizzlesloth>
|
||||
- Arya Singh - <https://github.com/ARYPROGRAMMER>
|
||||
- Xianglin Zeng - <https://github.com/FutureYL3>
|
||||
- Sangharsh Sulke - <https://github.com/Sangharshdeveloper>
|
||||
|
||||
## Translators
|
||||
|
||||
|
||||
@@ -913,4 +913,5 @@
|
||||
"@indicatorAvg": {
|
||||
"description": "added for localization of Class Indicator's field text"
|
||||
}
|
||||
"dark_mode":"Dark Mode",
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ class MyApp extends StatelessWidget {
|
||||
darkTheme: wgerDarkTheme,
|
||||
highContrastTheme: wgerLightThemeHc,
|
||||
highContrastDarkTheme: wgerDarkThemeHc,
|
||||
themeMode: auth.themeMode, // Change theme based on provider's themeMode
|
||||
themeMode: ThemeMode.system,
|
||||
home: auth.isAuth
|
||||
? const HomeTabsScreen()
|
||||
: FutureBuilder(
|
||||
|
||||
@@ -57,10 +57,10 @@ class AuthProvider with ChangeNotifier {
|
||||
_loadThemeMode();
|
||||
}
|
||||
|
||||
bool _isSwitched = false;
|
||||
bool _isLightTheme = false;
|
||||
ThemeMode _themeMode = ThemeMode.light;
|
||||
|
||||
bool get isSwitched => _isSwitched;
|
||||
bool get isSwitched => _isLightTheme;
|
||||
ThemeMode get themeMode => _themeMode;
|
||||
|
||||
/// flag to indicate that the application has successfully loaded all initial data
|
||||
@@ -75,18 +75,18 @@ class AuthProvider with ChangeNotifier {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final isDarkMode = prefs.getBool('isDarkMode') ?? false; // Default to false (light mode)
|
||||
_themeMode = isDarkMode ? ThemeMode.dark : ThemeMode.light;
|
||||
_isSwitched = isDarkMode;
|
||||
_isLightTheme = isDarkMode;
|
||||
notifyListeners(); // Notify listeners when theme is loaded
|
||||
}
|
||||
|
||||
// Change mode on switch button click
|
||||
void toggleSwitch(bool value) async {
|
||||
_isSwitched = value;
|
||||
_isLightTheme = value;
|
||||
_themeMode = value ? ThemeMode.dark : ThemeMode.light;
|
||||
|
||||
// Save to SharedPreferences
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool('isDarkMode', _isSwitched);
|
||||
await prefs.setBool('isDarkMode', _isLightTheme);
|
||||
|
||||
notifyListeners(); // Notify listeners when the theme is updated
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ class SettingsPage extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('Dark Mode'),
|
||||
title: Text(AppLocalizations.of(context).darkMode),
|
||||
trailing: Switch(
|
||||
value: switchProvider.isSwitched, // Use the state from the provider
|
||||
onChanged: (value) {
|
||||
|
||||
Reference in New Issue
Block a user