diff --git a/lib/core/viewModel/SOAP_view_model.dart b/lib/core/viewModel/SOAP_view_model.dart index e6820d72..1306b7ca 100644 --- a/lib/core/viewModel/SOAP_view_model.dart +++ b/lib/core/viewModel/SOAP_view_model.dart @@ -519,8 +519,8 @@ class SOAPViewModel extends BaseViewModel { setState(ViewState.Idle); } - onAddMedicationStart() async { - setState(ViewState.Busy); + Future onAddMedicationStart({required bool allowSetState}) async { + if (allowSetState) setState(ViewState.Busy); List services = []; if (medicationStrengthList.length == 0) { if (services.isEmpty) { @@ -562,9 +562,8 @@ class SOAPViewModel extends BaseViewModel { if (_SOAPService.hasError || _prescriptionService.hasError) { error = _SOAPService.error! + _prescriptionService.error!; - setState(ViewState.ErrorLocal); - } else - setState(ViewState.Idle); + if (allowSetState) setState(ViewState.ErrorLocal); + } else if (allowSetState) setState(ViewState.Idle); } callAddAssessmentLookupsServices({String searchKey = "", bool allowSetState = true}) async { diff --git a/lib/screens/patients/profile/soap_update/subjective/medication/add_medication.dart b/lib/screens/patients/profile/soap_update/subjective/medication/add_medication.dart index dcf3ace5..694645db 100644 --- a/lib/screens/patients/profile/soap_update/subjective/medication/add_medication.dart +++ b/lib/screens/patients/profile/soap_update/subjective/medication/add_medication.dart @@ -53,8 +53,10 @@ class _AddMedicationState extends State { ProjectViewModel projectViewModel = Provider.of(context); return FractionallySizedBox( child: BaseView( - onModelReady: (model) { - if (!mounted) model.onAddMedicationStart(); + onModelReady: (model) async { + model.onAddMedicationStart(allowSetState: false).whenComplete(() { + setState(() {}); + }); }, builder: (_, model, w) => AppScaffold( baseViewModel: model,