From fd3f15257f6d1eff019f310dd50ae27c6b3eb7f0 Mon Sep 17 00:00:00 2001 From: tamara-slosarek Date: Tue, 28 Nov 2023 14:58:00 +0100 Subject: [PATCH] fix(app): fix hot restart with activeDrugs and add comment --- app/lib/common/models/userdata/userdata.dart | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/lib/common/models/userdata/userdata.dart b/app/lib/common/models/userdata/userdata.dart index 2f94ec68..4bfd8033 100644 --- a/app/lib/common/models/userdata/userdata.dart +++ b/app/lib/common/models/userdata/userdata.dart @@ -171,8 +171,15 @@ class UserData { } } +// Wrapper of UserData.instance.activeDrugNames that manages changes; used to +// notify inactive tabs in case of changes. Should be refacored to ensure +// consistent use accross the app, see +// https://github.com/hpi-dhc/PharMe/issues/680 class ActiveDrugs extends ChangeNotifier { - List names = []; + ActiveDrugs() { + names = UserData.instance.activeDrugNames ?? []; + } + late List names; Future _preserveAndNotify() async { UserData.instance.activeDrugNames = names; @@ -207,6 +214,10 @@ class ActiveDrugs extends ChangeNotifier { bool contains(String drugName) { return names.contains(drugName); } + + bool isNotEmpty() { + return names.isNotEmpty; + } } /// Initializes the user's data by registering all necessary adapters and