added nullable chess time property in shared prefs
parent
ac994ad6e0
commit
acfb9fea70
|
@ -15,8 +15,9 @@ class Settings {
|
||||||
relapseCategories = jsonPropertyAsList(json['relapse_categories']),
|
relapseCategories = jsonPropertyAsList(json['relapse_categories']),
|
||||||
moodQuery = QueryConfig.fromJson(json['mood_query']),
|
moodQuery = QueryConfig.fromJson(json['mood_query']),
|
||||||
sleepQuery = QueryConfig.fromJson(json['sleep_query']),
|
sleepQuery = QueryConfig.fromJson(json['sleep_query']),
|
||||||
chessTime =
|
chessTime = json['chess_time'] != null
|
||||||
json['chess_time'] ? TimeConfig.fromJson(json['chess_time']) : null;
|
? TimeConfig.fromJson(json['chess_time'])
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
class QueryConfig {
|
class QueryConfig {
|
||||||
|
|
|
@ -20,6 +20,9 @@ Future<List<String>?> getMoodQueryDaysCategories() =>
|
||||||
Future<int?> getMoodQueryHours() => _getIntSetting('mood_query_hours');
|
Future<int?> getMoodQueryHours() => _getIntSetting('mood_query_hours');
|
||||||
Future<int?> getMoodQueryMinutes() => _getIntSetting('mood_query_minutes');
|
Future<int?> getMoodQueryMinutes() => _getIntSetting('mood_query_minutes');
|
||||||
|
|
||||||
|
Future<int?> getChessHours() => _getIntSetting('chess_hours');
|
||||||
|
Future<int?> getChessMinutes() => _getIntSetting('chess_minutes');
|
||||||
|
|
||||||
void _setStringSetting(String settingKey, String settingValue) =>
|
void _setStringSetting(String settingKey, String settingValue) =>
|
||||||
SharedPreferences.getInstance()
|
SharedPreferences.getInstance()
|
||||||
.then((pref) => pref.setString(settingKey, settingValue));
|
.then((pref) => pref.setString(settingKey, settingValue));
|
||||||
|
@ -42,10 +45,6 @@ Future<List<String>?> _getStringListSetting(String settingKey) =>
|
||||||
SharedPreferences.getInstance()
|
SharedPreferences.getInstance()
|
||||||
.then((pref) => pref.getStringList(settingKey));
|
.then((pref) => pref.getStringList(settingKey));
|
||||||
|
|
||||||
//Add other setters and getters if needed
|
|
||||||
//other possible SharedPreferences Types: Int, Bool, Double, StringList
|
|
||||||
//see https://pub.dev/packages/shared_preferences
|
|
||||||
|
|
||||||
Future<void> loadSettings() async {
|
Future<void> loadSettings() async {
|
||||||
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
|
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
|
||||||
Settings settings = Settings.fromJson(configJSON);
|
Settings settings = Settings.fromJson(configJSON);
|
||||||
|
@ -61,4 +60,8 @@ void saveSettings(Settings settings) {
|
||||||
_setStringListSetting('sleep_query_days', settings.sleepQuery.days!);
|
_setStringListSetting('sleep_query_days', settings.sleepQuery.days!);
|
||||||
_setIntSetting('sleep_query_hours', settings.sleepQuery.hours);
|
_setIntSetting('sleep_query_hours', settings.sleepQuery.hours);
|
||||||
_setIntSetting('sleep_query_minutes', settings.sleepQuery.minutes);
|
_setIntSetting('sleep_query_minutes', settings.sleepQuery.minutes);
|
||||||
|
if (settings.chessTime != null) {
|
||||||
|
_setIntSetting('chess_hours', settings.chessTime!.hours);
|
||||||
|
_setIntSetting('chess_minutes', settings.chessTime!.minutes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue