From abcd207554b07a839f209055b9d22461bc1dc6a6 Mon Sep 17 00:00:00 2001 From: Sultan Khan Date: Wed, 1 Sep 2021 11:39:00 +0300 Subject: [PATCH] schedule page fix --- lib/core/service/medical/medical_service.dart | 33 +--- .../medical/medical_view_model.dart | 42 +++-- lib/pages/MyAppointments/SchedulePage.dart | 155 +++++++----------- 3 files changed, 84 insertions(+), 146 deletions(-) diff --git a/lib/core/service/medical/medical_service.dart b/lib/core/service/medical/medical_service.dart index 5888fa0d..7e7cbe13 100644 --- a/lib/core/service/medical/medical_service.dart +++ b/lib/core/service/medical/medical_service.dart @@ -19,12 +19,10 @@ class MedicalService extends BaseService { body['isDentalAllowedBackend'] = false; } - await baseAppClient.post(GET_PATIENT_APPOINTMENT_HISTORY, - onSuccess: (response, statusCode) async { + await baseAppClient.post(GET_PATIENT_APPOINTMENT_HISTORY, onSuccess: (response, statusCode) async { appoitmentAllHistoryResultList.clear(); response['AppoimentAllHistoryResultList'].forEach((appoitment) { - appoitmentAllHistoryResultList - .add(AppoitmentAllHistoryResultList.fromJson(appoitment)); + appoitmentAllHistoryResultList.add(AppoitmentAllHistoryResultList.fromJson(appoitment)); }); }, onFailure: (String error, int statusCode) { hasError = true; @@ -39,9 +37,7 @@ class MedicalService extends BaseService { body['RequesterFileNo'] = user.patientID; body['RequesterMobileNo'] = user.mobileNumber; body['RequesterIsOutSA'] = user.outSA; - await baseAppClient.post(GET_PATIENT_APPOINTMENT_HISTORY, - onSuccess: (response, statusCode) async {}, - onFailure: (String error, int statusCode) { + await baseAppClient.post(GET_PATIENT_APPOINTMENT_HISTORY, onSuccess: (response, statusCode) async {}, onFailure: (String error, int statusCode) { hasError = true; super.error = error; }, body: body); @@ -49,35 +45,22 @@ class MedicalService extends BaseService { getSchedule(DoctorList doctorRequest) async { Map request; - request = { - 'DoctorID': doctorRequest.doctorID, - 'ProjectID': doctorRequest.projectID, - 'ClinicID': doctorRequest.clinicID, - 'DoctorWorkingHoursDays': 7 - }; + request = {'DoctorID': doctorRequest.doctorID, 'ProjectID': doctorRequest.projectID, 'ClinicID': doctorRequest.clinicID, 'DoctorWorkingHoursDays': 7}; dynamic localRes; - await baseAppClient.post(DOCTOR_SCHEDULE_URL, - onSuccess: (response, statusCode) async { + await baseAppClient.post(DOCTOR_SCHEDULE_URL, onSuccess: (response, statusCode) async { localRes = response; }, onFailure: (String error, int statusCode) { throw error; }, body: request); doctorScheduleResponse.clear(); - localRes['List_DoctorWorkingHoursTable'].forEach((item) => - {doctorScheduleResponse.add(DoctorScheduleResponse.fromJson(item))}); + localRes['List_DoctorWorkingHoursTable'].forEach((item) => {doctorScheduleResponse.add(DoctorScheduleResponse.fromJson(item))}); } getFreeSlot(DoctorList doctorRequest) async { Map request; - request = { - 'DoctorID': doctorRequest.doctorID, - 'ProjectID': doctorRequest.projectID, - 'ClinicID': doctorRequest.clinicID, - 'DoctorWorkingHoursDays': 7 - }; + request = {'DoctorID': doctorRequest.doctorID, 'ProjectID': doctorRequest.projectID, 'ClinicID': doctorRequest.clinicID, 'DoctorWorkingHoursDays': 7}; dynamic localRes; - await baseAppClient.post(GET_DOCTOR_FREE_SLOTS, - onSuccess: (response, statusCode) async { + await baseAppClient.post(GET_DOCTOR_FREE_SLOTS, onSuccess: (response, statusCode) async { localRes = response; }, onFailure: (String error, int statusCode) { throw error; diff --git a/lib/core/viewModels/medical/medical_view_model.dart b/lib/core/viewModels/medical/medical_view_model.dart index 647982d1..5099e914 100644 --- a/lib/core/viewModels/medical/medical_view_model.dart +++ b/lib/core/viewModels/medical/medical_view_model.dart @@ -10,10 +10,8 @@ import 'package:diplomaticquarterapp/pages/MyAppointments/models/DoctorScheduleR class MedicalViewModel extends BaseViewModel { MedicalService _medicalService = locator(); - List get appoitmentAllHistoryResultList => - _medicalService.appoitmentAllHistoryResultList; - List get getDoctorScheduleList => - _medicalService.doctorScheduleResponse; + List get appoitmentAllHistoryResultList => _medicalService.appoitmentAllHistoryResultList; + List get getDoctorScheduleList => _medicalService.doctorScheduleResponse; List get freeSlots => _medicalService.freeSlots; getAppointmentHistory() async { if (authenticatedUserObject.isLogin) { @@ -28,26 +26,26 @@ class MedicalViewModel extends BaseViewModel { } getDoctorSchedule(DoctorList doctorRequest) async { - if (authenticatedUserObject.isLogin) { - setState(ViewState.Busy); - await _medicalService.getSchedule(doctorRequest); - if (_medicalService.hasError) { - error = _medicalService.error; - setState(ViewState.Error); - } else - setState(ViewState.Idle); - } + //if (authenticatedUserObject.isLogin) { + setState(ViewState.Busy); + await _medicalService.getSchedule(doctorRequest); + if (_medicalService.hasError) { + error = _medicalService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); + //} } getFreeSlots(DoctorList doctorRequest) async { - if (authenticatedUserObject.isLogin) { - setState(ViewState.Busy); - await _medicalService.getFreeSlot(doctorRequest); - if (_medicalService.hasError) { - error = _medicalService.error; - setState(ViewState.Error); - } else - setState(ViewState.Idle); - } + //if (authenticatedUserObject.isLogin) { + setState(ViewState.Busy); + await _medicalService.getFreeSlot(doctorRequest); + if (_medicalService.hasError) { + error = _medicalService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); } + //} } diff --git a/lib/pages/MyAppointments/SchedulePage.dart b/lib/pages/MyAppointments/SchedulePage.dart index 1c46e7e8..4283432f 100644 --- a/lib/pages/MyAppointments/SchedulePage.dart +++ b/lib/pages/MyAppointments/SchedulePage.dart @@ -51,8 +51,10 @@ class _SchedulePageState extends State { Widget build(BuildContext context) { return BaseView( onModelReady: (model) => model.getDoctorSchedule(doctorList), + allowAny: true, builder: (_, model, widget) => BaseView( onModelReady: (model2) => model2.getFreeSlots(doctorList), + allowAny: true, builder: (_, model2, widget2) { if (model.freeSlots.length > 0 && isPageChange == false) { this.freeSlots = model.freeSlots; @@ -84,101 +86,59 @@ class _SchedulePageState extends State { return Container( child: ListView.builder( itemCount: weeks[index].length, - itemBuilder: (context, index2) => - InkWell( - onTap: () { - openBookAppointment( - weeks[index][index2]); - }, - child: Row( - children: [ - Expanded( - flex: 1, - child: Padding( - padding: - EdgeInsets.only( - left: 20), + itemBuilder: (context, index2) => InkWell( + onTap: () { + openBookAppointment(weeks[index][index2]); + }, + child: Row( + children: [ + Expanded( + flex: 1, + child: Padding( + padding: EdgeInsets.only(left: 20), + child: Row(children: [ + Column( + children: [ + Texts( + weeks[index][index2]['DayName'], + fontSize: 13, + ), + Texts( + getDayMonths( + DateUtil.convertStringToDate( + weeks[index][index2]['Date'], + ), + ), + fontWeight: FontWeight.bold, + fontSize: 18, + ) + ], + ) + ])), + ), + Expanded( + flex: 3, + child: ClipRRect( + borderRadius: const BorderRadius.all(Radius.circular(20.0)), + child: Container( + padding: EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 20), + margin: EdgeInsets.only(left: 20, right: 20, top: 7, bottom: 7), + decoration: BoxDecoration(boxShadow: [ + weeks[index][index2]['fullDay'] == false ? BoxShadow(color: Colors.green, offset: Offset(-5, 0)) : BoxShadow(), + ], borderRadius: const BorderRadius.all(Radius.circular(10.0)), color: Colors.white), child: Row( - children: [ - Column( - children: [ - Texts( - weeks[index][index2] - [ - 'DayName'], - fontSize: - 13, - ), - Texts( - getDayMonths( - DateUtil - .convertStringToDate( - weeks[index][index2]['Date'], - ), - ), - fontWeight: - FontWeight.bold, - fontSize: - 18, - ) - ], - ) - ])), - ), - Expanded( - flex: 3, - child: ClipRRect( - borderRadius: - const BorderRadius - .all( - Radius.circular( - 20.0)), - child: Container( - padding: - EdgeInsets.only( - left: - 10, - right: - 10, - top: 20, - bottom: - 20), - margin: EdgeInsets.only( - left: 20, - right: 20, - top: 7, - bottom: 7), - decoration: BoxDecoration( - boxShadow: [ - weeks[index][index2]['fullDay'] == - false - ? BoxShadow( - color: Colors.green, - offset: Offset(-5, 0)) - : BoxShadow(), - ], - borderRadius: - const BorderRadius.all(Radius.circular( - 10.0)), - color: Colors - .white), - child: Row( - children: [ - Expanded( - child: - Texts( - weeks[index][index2] - [ - 'WorkingHours'], - fontWeight: - FontWeight.w400, - ), - ) - ], - ))), - ) - ], - )))); + children: [ + Expanded( + child: Texts( + weeks[index][index2]['WorkingHours'], + fontWeight: FontWeight.w400, + ), + ) + ], + ))), + ) + ], + )))); }, )), PageViewIndicator( @@ -213,9 +173,7 @@ class _SchedulePageState extends State { var newWeekSchedule = []; for (var workDay in this.doctorScheduleResponse) { Map newWorkDay = Map(); - newWorkDay['Date'] = DateUtil.convertDateMSToJsonDate( - DateUtil.convertStringToDate(workDay.date).millisecondsSinceEpoch + - weekMSOffset); + newWorkDay['Date'] = DateUtil.convertDateMSToJsonDate(DateUtil.convertStringToDate(workDay.date).millisecondsSinceEpoch + weekMSOffset); newWorkDay['DayName'] = workDay.dayName; newWorkDay['WorkingHours'] = workDay.workingHours; newWeekSchedule.add(newWorkDay); @@ -238,8 +196,7 @@ class _SchedulePageState extends State { } String getDayMonths(DateTime dateTime) { - String dateFormat = - '${dateTime.day} ${DateUtil.getMonth(dateTime.month).toString().substring(0, 3)}'; + String dateFormat = '${dateTime.day} ${DateUtil.getMonth(dateTime.month).toString().substring(0, 3)}'; return dateFormat; }