aboutsummaryrefslogtreecommitdiff
path: root/lib/data
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/data/config.dart51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/data/config.dart b/lib/data/config.dart
new file mode 100644
index 0000000..0dd33cd
--- /dev/null
+++ b/lib/data/config.dart
@@ -0,0 +1,51 @@
+import 'package:shared_preferences/shared_preferences.dart';
+import 'dart:async';
+
+String defaultTheme = 'dark';
+
+class Config {
+ String theme = defaultTheme;
+ Config({ this.theme }) {}
+
+ bool isDarkMode() {
+ return theme == 'dark';
+ }
+}
+
+StreamController<Config> config_$ = StreamController<Config>.broadcast();
+
+Future<Config> getConfig() async {
+ final prefs = await SharedPreferences.getInstance();
+
+ return Config(
+ theme: prefs.getString('theme'),
+ );
+}
+
+void initConfig() async {
+ Config c = await getConfig();
+ config_$.add(c);
+}
+
+Stream<Config> getConfig$() {
+ return config_$.stream;
+}
+
+void setConfig(Config config) async {
+ final prefs = await SharedPreferences.getInstance();
+
+ prefs.setString('theme', config.theme);
+
+ config_$.add(await getConfig());
+}
+
+void toggleTheme() async {
+ final config = await getConfig();
+
+ if (config.theme == 'dark') {
+ setConfig(Config(theme: 'light'));
+ } else {
+ setConfig(Config(theme: 'dark'));
+ }
+}
+