diff --git a/lib/models/settings.dart b/lib/models/settings.dart index 0282083..359338f 100644 --- a/lib/models/settings.dart +++ b/lib/models/settings.dart @@ -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 { diff --git a/lib/service/settings_service.dart b/lib/service/settings_service.dart index ead6f9b..891f60b 100644 --- a/lib/service/settings_service.dart +++ b/lib/service/settings_service.dart @@ -20,6 +20,9 @@ Future?> getMoodQueryDaysCategories() => Future getMoodQueryHours() => _getIntSetting('mood_query_hours'); Future getMoodQueryMinutes() => _getIntSetting('mood_query_minutes'); +Future getChessHours() => _getIntSetting('chess_hours'); +Future getChessMinutes() => _getIntSetting('chess_minutes'); + void _setStringSetting(String settingKey, String settingValue) => SharedPreferences.getInstance() .then((pref) => pref.setString(settingKey, settingValue)); @@ -42,10 +45,6 @@ Future?> _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 loadSettings() async { Map 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); + } }