return null if settings cant be correctly loaded

main
Kai Mannweiler 2023-02-27 11:39:42 +01:00
parent 21470da038
commit 9c4a5e0fbb
2 changed files with 11 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import 'package:smoke_cess_app/services/json_service.dart'; import 'package:smoke_cess_app/services/json_service.dart';
class Settings { class Settings {
final int? group; final int group;
final List<String>? relapseCategories; final List<String>? relapseCategories;
final QueryConfig? moodQuery; final QueryConfig? moodQuery;
final QueryConfig? sleepQuery; final QueryConfig? sleepQuery;

View File

@ -66,7 +66,7 @@ void saveSettings(Settings settings) {
} }
} }
Future<Settings> loadSettings() async { Future<Settings?> loadSettings() async {
int? group = await getGroup(); int? group = await getGroup();
List<String>? relapseCategories = await getRelapseCategories(); List<String>? relapseCategories = await getRelapseCategories();
int? moodHours = await getMoodQueryHours(); int? moodHours = await getMoodQueryHours();
@ -78,10 +78,13 @@ Future<Settings> loadSettings() async {
int? chessHours = await getChessHours(); int? chessHours = await getChessHours();
int? chessMinutes = await getChessMinutes(); int? chessMinutes = await getChessMinutes();
if (group != null) {
return Settings( return Settings(
group, group,
relapseCategories, relapseCategories,
QueryConfig(moodHours, moodMinutes, moodDays), QueryConfig(moodHours, moodMinutes, moodDays),
QueryConfig(sleepHours, sleepMinutes, sleepDays), QueryConfig(sleepHours, sleepMinutes, sleepDays),
TimeConfig(chessHours, chessMinutes)); TimeConfig(chessHours, chessMinutes));
}
return null;
} }