outsource loadsettings to settings_service

main
Kai Mannweiler 2023-02-27 11:27:45 +01:00
parent d46dd3ff7b
commit 21470da038
2 changed files with 22 additions and 18 deletions

View File

@ -15,24 +15,8 @@ class SettingsProvider extends ChangeNotifier {
}
void initSettings() async {
int? group = await getGroup();
List<String>? relapseCategories = await getRelapseCategories();
int? moodHours = await getMoodQueryHours();
int? moodMinutes = await getMoodQueryMinutes();
List<String>? moodDays = await getMoodQueryDaysCategories();
int? sleepHours = await getSleepQueryHours();
int? sleepMinutes = await getSleepQueryMinutes();
List<String>? sleepDays = await getSleepQueryDaysCategories();
int? chessHours = await getChessHours();
int? chessMinutes = await getChessMinutes();
_settings = Settings(
group,
relapseCategories,
QueryConfig(moodHours, moodMinutes, moodDays),
QueryConfig(sleepHours, sleepMinutes, sleepDays),
TimeConfig(chessHours, chessMinutes));
_initialized = group != null ? true : false;
_settings = await loadSettings();
_initialized = _settings != null ? true : false;
notifyListeners();
}
}

View File

@ -65,3 +65,23 @@ void saveSettings(Settings settings) {
_setIntSetting('chess_minutes', settings.chessTime!.minutes!);
}
}
Future<Settings> loadSettings() async {
int? group = await getGroup();
List<String>? relapseCategories = await getRelapseCategories();
int? moodHours = await getMoodQueryHours();
int? moodMinutes = await getMoodQueryMinutes();
List<String>? moodDays = await getMoodQueryDaysCategories();
int? sleepHours = await getSleepQueryHours();
int? sleepMinutes = await getSleepQueryMinutes();
List<String>? sleepDays = await getSleepQueryDaysCategories();
int? chessHours = await getChessHours();
int? chessMinutes = await getChessMinutes();
return Settings(
group,
relapseCategories,
QueryConfig(moodHours, moodMinutes, moodDays),
QueryConfig(sleepHours, sleepMinutes, sleepDays),
TimeConfig(chessHours, chessMinutes));
}