From 9c4a5e0fbb69921a967f92037a4891642ce5b2ab Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 27 Feb 2023 11:39:42 +0100 Subject: [PATCH] return null if settings cant be correctly loaded --- lib/models/settings.dart | 2 +- lib/services/settings_service.dart | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/models/settings.dart b/lib/models/settings.dart index 7dea33f..83fad43 100644 --- a/lib/models/settings.dart +++ b/lib/models/settings.dart @@ -1,7 +1,7 @@ import 'package:smoke_cess_app/services/json_service.dart'; class Settings { - final int? group; + final int group; final List? relapseCategories; final QueryConfig? moodQuery; final QueryConfig? sleepQuery; diff --git a/lib/services/settings_service.dart b/lib/services/settings_service.dart index d72c245..13de7f6 100644 --- a/lib/services/settings_service.dart +++ b/lib/services/settings_service.dart @@ -66,7 +66,7 @@ void saveSettings(Settings settings) { } } -Future loadSettings() async { +Future loadSettings() async { int? group = await getGroup(); List? relapseCategories = await getRelapseCategories(); int? moodHours = await getMoodQueryHours(); @@ -78,10 +78,13 @@ Future loadSettings() async { int? chessHours = await getChessHours(); int? chessMinutes = await getChessMinutes(); - return Settings( - group, - relapseCategories, - QueryConfig(moodHours, moodMinutes, moodDays), - QueryConfig(sleepHours, sleepMinutes, sleepDays), - TimeConfig(chessHours, chessMinutes)); + if (group != null) { + return Settings( + group, + relapseCategories, + QueryConfig(moodHours, moodMinutes, moodDays), + QueryConfig(sleepHours, sleepMinutes, sleepDays), + TimeConfig(chessHours, chessMinutes)); + } + return null; }