From 21470da038398f4184aeaa90d632f4654f02024b Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 27 Feb 2023 11:27:45 +0100 Subject: [PATCH] outsource loadsettings to settings_service --- lib/providers/settings_provider.dart | 20 ++------------------ lib/services/settings_service.dart | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/providers/settings_provider.dart b/lib/providers/settings_provider.dart index 5283808..f51c5e1 100644 --- a/lib/providers/settings_provider.dart +++ b/lib/providers/settings_provider.dart @@ -15,24 +15,8 @@ class SettingsProvider extends ChangeNotifier { } void initSettings() async { - int? group = await getGroup(); - List? relapseCategories = await getRelapseCategories(); - int? moodHours = await getMoodQueryHours(); - int? moodMinutes = await getMoodQueryMinutes(); - List? moodDays = await getMoodQueryDaysCategories(); - int? sleepHours = await getSleepQueryHours(); - int? sleepMinutes = await getSleepQueryMinutes(); - List? 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(); } } diff --git a/lib/services/settings_service.dart b/lib/services/settings_service.dart index c046cd2..d72c245 100644 --- a/lib/services/settings_service.dart +++ b/lib/services/settings_service.dart @@ -65,3 +65,23 @@ void saveSettings(Settings settings) { _setIntSetting('chess_minutes', settings.chessTime!.minutes!); } } + +Future loadSettings() async { + int? group = await getGroup(); + List? relapseCategories = await getRelapseCategories(); + int? moodHours = await getMoodQueryHours(); + int? moodMinutes = await getMoodQueryMinutes(); + List? moodDays = await getMoodQueryDaysCategories(); + int? sleepHours = await getSleepQueryHours(); + int? sleepMinutes = await getSleepQueryMinutes(); + List? 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)); +}