added nullable chess time property in shared prefs

main
Julian Gegner 2023-02-19 17:44:20 +01:00
parent ac994ad6e0
commit acfb9fea70
2 changed files with 10 additions and 6 deletions

View File

@ -15,8 +15,9 @@ class Settings {
relapseCategories = jsonPropertyAsList(json['relapse_categories']),
moodQuery = QueryConfig.fromJson(json['mood_query']),
sleepQuery = QueryConfig.fromJson(json['sleep_query']),
chessTime =
json['chess_time'] ? TimeConfig.fromJson(json['chess_time']) : null;
chessTime = json['chess_time'] != null
? TimeConfig.fromJson(json['chess_time'])
: null;
}
class QueryConfig {

View File

@ -20,6 +20,9 @@ Future<List<String>?> getMoodQueryDaysCategories() =>
Future<int?> getMoodQueryHours() => _getIntSetting('mood_query_hours');
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) =>
SharedPreferences.getInstance()
.then((pref) => pref.setString(settingKey, settingValue));
@ -42,10 +45,6 @@ Future<List<String>?> _getStringListSetting(String settingKey) =>
SharedPreferences.getInstance()
.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 {
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
Settings settings = Settings.fromJson(configJSON);
@ -61,4 +60,8 @@ void saveSettings(Settings settings) {
_setStringListSetting('sleep_query_days', settings.sleepQuery.days!);
_setIntSetting('sleep_query_hours', settings.sleepQuery.hours);
_setIntSetting('sleep_query_minutes', settings.sleepQuery.minutes);
if (settings.chessTime != null) {
_setIntSetting('chess_hours', settings.chessTime!.hours);
_setIntSetting('chess_minutes', settings.chessTime!.minutes);
}
}