#687 enhancement theme-customization

This commit is contained in:
sangharshdeveloper
2025-01-17 22:19:54 +05:30
parent ced268660b
commit 06ca72e0f8
5 changed files with 9 additions and 7 deletions

View File

@@ -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

View File

@@ -913,4 +913,5 @@
"@indicatorAvg": {
"description": "added for localization of Class Indicator's field text"
}
"dark_mode":"Dark Mode",
}

View File

@@ -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(

View File

@@ -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
}

View File

@@ -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) {