From e10c07f6a46603f8ee8c5775012f04a18db69933 Mon Sep 17 00:00:00 2001 From: RoaaGhali98 Date: Thu, 3 Feb 2022 09:02:14 +0200 Subject: [PATCH] fix loader in prescriptions_page --- lib/core/viewModel/patient_view_model.dart | 29 ++++++++-- .../prescription/prescriptions_page.dart | 54 ++++++++++--------- 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/lib/core/viewModel/patient_view_model.dart b/lib/core/viewModel/patient_view_model.dart index 9457ed99..0336a3cd 100644 --- a/lib/core/viewModel/patient_view_model.dart +++ b/lib/core/viewModel/patient_view_model.dart @@ -18,6 +18,8 @@ import 'package:doctor_app_flutter/core/model/patient/prescription/prescription_ import 'package:doctor_app_flutter/core/model/patient/prescription/prescription_res_model.dart'; import 'package:doctor_app_flutter/core/model/patient/radiology/radiology_res_model.dart'; import 'package:doctor_app_flutter/core/model/patient/vital_sign/vital_sign_res_model.dart'; +import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; +import 'package:flutter/cupertino.dart'; import '../../locator.dart'; import 'base_view_model.dart'; @@ -101,16 +103,37 @@ class PatientViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future getOutPatientPrescriptions(patient) async { - setState(ViewState.Busy); + Future getOutPatientPrescriptions(patient, {bool isLocalBusy = false, BuildContext context, PatiantInformtion patientInformation}) async { + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } + GifLoaderDialogUtils.showMyDialog(context); await _patientService.getOutPatientPrescriptions(patient); + GifLoaderDialogUtils.hideDialog(context); if (_patientService.hasError) { error = _patientService.error; - setState(ViewState.Error); + if (isLocalBusy) { + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Error); + } } else setState(ViewState.Idle); } + + // async { + // setState(ViewState.Busy); + // await _patientService.getOutPatientPrescriptions(patient); + // if (_patientService.hasError) { + // error = _patientService.error; + // setState(ViewState.Error); + // } else + // setState(ViewState.Idle); + // } + Future getInPatientPrescriptions(patient) async { setState(ViewState.Busy); await _patientService.getInPatientPrescriptions(patient); diff --git a/lib/screens/prescription/prescriptions_page.dart b/lib/screens/prescription/prescriptions_page.dart index 1486efba..58bad8bc 100644 --- a/lib/screens/prescription/prescriptions_page.dart +++ b/lib/screens/prescription/prescriptions_page.dart @@ -1,3 +1,4 @@ +import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart'; import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; @@ -26,6 +27,7 @@ class PrescriptionsPage extends StatelessWidget { @override Widget build(BuildContext context) { final routeArgs = ModalRoute.of(context).settings.arguments as Map; + PatientViewModel patientViewModel; PatiantInformtion patient = routeArgs['patient']; String patientType = routeArgs['patientType']; String arrivalType = routeArgs['arrivalType']; @@ -33,9 +35,16 @@ class PrescriptionsPage extends StatelessWidget { bool isFromLiveCare = routeArgs['isFromLiveCare']; bool isSelectInpatient = routeArgs['isSelectInpatient']; return BaseView( - onModelReady: (model) => patient.admissionNo == null - ? model.getPrescriptions(patient, patientType: patientType) - : model.getMedicationForInPatient(patient), + onModelReady: (model) async { + await model.getOutPatientPrescriptions( + patient.admissionNo == null + ? model.getPrescriptions(patient, patientType: patientType) + : model.getMedicationForInPatient(patient), + isLocalBusy: false, + context: context, + patientInformation: patient + ); + }, builder: (_, model, w) => AppScaffold( baseViewModel: model, isShowAppBar: true, @@ -118,29 +127,24 @@ class PrescriptionsPage extends StatelessWidget { ), ), ), - child: Container( - child: Column( - children: [ - AppText( - model.prescriptionsList[index].despensedStatus, - ), - DoctorCard( - doctorName: - model.prescriptionsList[index].doctorName, - profileUrl: model - .prescriptionsList[index].doctorImageURL, - branch: model.prescriptionsList[index].name, - clinic: model.prescriptionsList[index] - .clinicDescription, - isPrescriptions: true, - appointmentDate: - AppDateUtils.getDateTimeFromServerFormat( - model.prescriptionsList[index] - .appointmentDate, - ), + child: Column( + children: [ + DoctorCard( + doctorName: + model.prescriptionsList[index].doctorName, + profileUrl: model + .prescriptionsList[index].doctorImageURL, + branch: model.prescriptionsList[index].name, + clinic: model.prescriptionsList[index] + .clinicDescription, + isPrescriptions: true, + appointmentDate: + AppDateUtils.getDateTimeFromServerFormat( + model.prescriptionsList[index] + .appointmentDate, ), - ], - ), + ), + ], ))), if (model.prescriptionsList.isEmpty && patient.patientStatusType != 43)