2020-08-30 22:43:16 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
part 'config_store.g.dart';
|
|
|
|
|
|
|
|
class ConfigStore extends _ConfigStore with _$ConfigStore {}
|
|
|
|
|
|
|
|
abstract class _ConfigStore with Store {
|
|
|
|
ReactionDisposer _saveReactionDisposer;
|
|
|
|
|
|
|
|
_ConfigStore() {
|
|
|
|
// persitently save settings each time they are changed
|
2020-08-31 16:17:39 +02:00
|
|
|
_saveReactionDisposer = reaction((_) => [theme], (_) {
|
2020-08-30 22:43:16 +02:00
|
|
|
save();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void dispose() {
|
|
|
|
_saveReactionDisposer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void load() async {
|
|
|
|
var prefs = await SharedPreferences.getInstance();
|
|
|
|
// set saved settings or create defaults
|
2020-08-31 17:52:16 +02:00
|
|
|
theme = _themeModeFromString(prefs.getString('theme') ?? 'system');
|
2020-08-30 22:43:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void save() async {
|
|
|
|
var prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
await prefs.setString('theme', describeEnum(theme));
|
|
|
|
}
|
|
|
|
|
|
|
|
@observable
|
2020-08-31 17:52:16 +02:00
|
|
|
ThemeMode theme;
|
2020-08-30 22:43:16 +02:00
|
|
|
|
|
|
|
@observable
|
2020-08-31 17:52:16 +02:00
|
|
|
MaterialColor accentColor;
|
2020-08-30 22:43:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ThemeMode _themeModeFromString(String theme) =>
|
|
|
|
ThemeMode.values.firstWhere((e) => describeEnum(e) == theme);
|