diff --git a/lib/screens/patients/profile/soap_update/subjective/allergies/update_allergies_widget.dart b/lib/screens/patients/profile/soap_update/subjective/allergies/update_allergies_widget.dart index 1083ed48..cb7d7d00 100644 --- a/lib/screens/patients/profile/soap_update/subjective/allergies/update_allergies_widget.dart +++ b/lib/screens/patients/profile/soap_update/subjective/allergies/update_allergies_widget.dart @@ -37,7 +37,7 @@ class _UpdateAllergiesWidgetState extends State { SOAPOpenItems(label: "${TranslationBase.of(context).addAllergies}",onTap: () { - openAllergiesList(context, changeAllState); + openAllergiesList(context, changeAllState, removeAllergy); },), SizedBox( height: 20, @@ -164,7 +164,7 @@ class _UpdateAllergiesWidgetState extends State { } } - openAllergiesList(BuildContext context, Function changeParentState) { + openAllergiesList(BuildContext context, Function changeParentState, removeAllergy) { showModalBottomSheet( backgroundColor: Colors.white, isScrollControlled: true, @@ -173,6 +173,7 @@ class _UpdateAllergiesWidgetState extends State { builder: (context) { return AddAllergies( myAllergiesList: widget.myAllergiesList, + addAllergiesFun: (List mySelectedAllergy) { bool isAllDataFilled = true; mySelectedAllergy.forEach((element) { @@ -187,6 +188,20 @@ class _UpdateAllergiesWidgetState extends State { widget.myAllergiesList.add(element); } }); + + /// remove items. + List removedList= []; + widget.myAllergiesList.forEach((element) { + if ((mySelectedAllergy.singleWhere((it) => it.selectedAllergy.id == element.selectedAllergy.id, + orElse: () => null)) == null) { + removedList.add(element); + }}); + + removedList.forEach((element) { + removeAllergy(element); + }); + + changeParentState(); Navigator.of(context).pop(); } else {