-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor theme declaration and introduce theme service (#8)
In theme_color_switch.dart, restructured the declaration of themes into a global constant 'appThemes', freeing it from a class field in ZetaThemeColorSwitch. This increases application efficiency and adheres to the DRY (Don't Repeat Yourself) principle. A new file 'theme_service.dart' was also added, serving as an abstract class for loading and saving theme data. Various typos in 'colors.dart' and 'zeta.dart' were fixed to ensure correct execution. Theme data loading and saving operations in 'main.dart' were also updated to use this new service.
- Loading branch information
1 parent
33b0c74
commit c7cffcf
Showing
12 changed files
with
149 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:flutter/src/material/app.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:zeta_example/pages/theme_color_switch.dart'; | ||
import 'package:zeta_flutter/zeta_flutter.dart'; | ||
|
||
class SharedPrefsThemeService extends ZetaThemeService { | ||
SharedPrefsThemeService(this.preferences); | ||
|
||
final SharedPreferences preferences; | ||
|
||
@override | ||
Future<(ZetaThemeData?, ThemeMode?, ZetaContrast?)> loadTheme() async { | ||
final theme = preferences.getString('theme') ?? 'default'; | ||
final themeData = appThemes[theme]; | ||
|
||
final modeString = preferences.getString('themeMode'); | ||
final themeMode = modeString == 'light' | ||
? ThemeMode.light | ||
: modeString == 'dark' | ||
? ThemeMode.dark | ||
: ThemeMode.system; | ||
|
||
final contrastString = preferences.getString('contrast'); | ||
final contrast = contrastString == 'aaa' ? ZetaContrast.aaa : ZetaContrast.aa; | ||
|
||
return (themeData, themeMode, contrast); | ||
} | ||
|
||
@override | ||
Future<void> saveTheme({ | ||
required ZetaThemeData themeData, | ||
required ThemeMode themeMode, | ||
required ZetaContrast contrast, | ||
}) async { | ||
await preferences.setString('theme', themeData.identifier); | ||
|
||
final modeString = themeMode == ThemeMode.light | ||
? 'light' | ||
: themeMode == ThemeMode.dark | ||
? 'dark' | ||
: 'system'; | ||
await preferences.setString('themeMode', modeString); | ||
|
||
final contrastString = contrast == ZetaContrast.aaa ? 'aaa' : 'aa'; | ||
await preferences.setString('contrast', contrastString); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters