From 2c746bf783c5f1289bb8919c6c508ceaa9ea3d2c Mon Sep 17 00:00:00 2001 From: sultan khan Date: Tue, 4 Mar 2025 11:18:29 +0300 Subject: [PATCH] next day appointments change. --- .../components/DocAvailableAppointments.dart | 151 ++++++++++++++++-- 1 file changed, 141 insertions(+), 10 deletions(-) diff --git a/lib/pages/BookAppointment/components/DocAvailableAppointments.dart b/lib/pages/BookAppointment/components/DocAvailableAppointments.dart index 6e12c68e..45db7f8b 100644 --- a/lib/pages/BookAppointment/components/DocAvailableAppointments.dart +++ b/lib/pages/BookAppointment/components/DocAvailableAppointments.dart @@ -45,16 +45,17 @@ class _DocAvailableAppointmentsState extends State wit AppSharedPreferences sharedPref = new AppSharedPreferences(); var selectedDate = ""; + var selectedNextDate = ""; dynamic selectedDateJSON; dynamic jsonFreeSlots; - + final DateFormat dateFormatter = DateFormat('yyyy-MM-dd'); List docFreeSlots = []; List dayEvents = []; - + List nextDayEvents = []; int selectedButtonIndex = 0; - + int selectedNextDayButtonIndex = -1; dynamic freeSlotsResponse; - + String nextDayAppointmentDate =""; late ScrollController _scrollController; var language; @@ -115,9 +116,11 @@ class _DocAvailableAppointmentsState extends State wit final DateFormat formatter = DateFormat('yyyy-MM-dd'); setState(() { this.selectedDate = DateUtil.getWeekDayMonthDayYearDateFormatted(day, language); + this.selectedNextDate = DateUtil.getWeekDayMonthDayYearDateFormatted(day.add(Duration(days: 1)), language); + _calendarController.selectedDate = day; openTimeSlotsPickerForDate(day, docFreeSlots); DocAvailableAppointments.selectedDate = formatter.format(day); - _calendarController.selectedDate = day; + nextDayAppointmentDate = formatter.format(day.add(Duration(days: 1))); print(_calendarController.selectedDate); }); } @@ -139,9 +142,12 @@ class _DocAvailableAppointmentsState extends State wit child: Text(selectedDate, style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w600, letterSpacing: -0.64)), ), DocAvailableAppointments.areSlotsAvailable - ? Container( + ? Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ Container( height: 40, - child: ListView.builder( + child: + ListView.builder( controller: _scrollController, scrollDirection: Axis.horizontal, itemCount: dayEvents.length, @@ -152,7 +158,30 @@ class _DocAvailableAppointmentsState extends State wit ); }, ), - ) + ), + SizedBox(height: 20,), + nextDayEvents.isNotEmpty ? Container( + padding: EdgeInsets.only(left: 20, right: 20, bottom:20), + child: Text(selectedNextDate, style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w600, letterSpacing: -0.46, color: CustomColors.black))) :SizedBox(), + Container( + height: 40, + padding: EdgeInsets.only(left: 0, right: 0), + child: + ListView.builder( + controller: _scrollController, + scrollDirection: Axis.horizontal, + itemCount: nextDayEvents.length, + itemBuilder: (context, index) { + return Container( + margin: EdgeInsets.only(right: (index == nextDayEvents.length - 1) ? 16 : 5.0, left: index == 0 ? 16 : 5), + child: index == selectedNextDayButtonIndex ? getSelectedNextDayButton(index) : getNormalNextDayButton(index), + ); + }, + ), + ) + ],) + + : Center( child: Padding( padding: const EdgeInsets.only(left: 12.0, right: 12.0), @@ -225,21 +254,34 @@ class _DocAvailableAppointmentsState extends State wit Map timeSlot = {"isoTime": dayEvents[i].isoTime, "start": dayEvents[i].start.toString(), "end": dayEvents[i].end.toString(), "vidaDate": dayEvents[i].vidaDate}; timeList.add(timeSlot); } - + filterNextDayAppo(freeSlots, timeList.last); AppSharedPreferences sharedPref = new AppSharedPreferences(); sharedPref.setString('selectedLogSlots', json.encode(timeList)); DocAvailableAppointments.selectedTime = dayEvents[selectedButtonIndex].isoTime; } else DocAvailableAppointments.areSlotsAvailable = false; }); + } + filterNextDayAppo(List freeSlots, Map listList){ + DateTime dateStart = DateTime.parse(listList['end']).add(Duration(hours: 6)); + DateTime dateStartObj = new DateTime(dateStart.year, dateStart.month, dateStart.day, 0, 0, 0, 0, 0); + nextDayEvents = []; + DateTime? previousDate = _calendarController.selectedDate != null ? _calendarController.selectedDate : _calendarController.displayDate; + // if(DateUtils.isSameDay(dateStart, previousDate!.add(Duration(days:1)) )) { + + freeSlots.forEach((v) { + if (v.start == dateStartObj && v.end!.isBefore(dateStart) ) nextDayEvents.add(v); + }); + print(nextDayEvents); + // } + } Future> _getJSONSlots() async { Map _eventsParsed; List slotsList = []; DateTime date; final DateFormat formatter = DateFormat('HH:mm'); - final DateFormat dateFormatter = DateFormat('yyyy-MM-dd'); for (var i = 0; i < freeSlotsResponse.length; i++) { date = (isLiveCareSchedule != null && isLiveCareSchedule) ? DateUtil.convertStringToDate(freeSlotsResponse[i]) @@ -259,6 +301,16 @@ class _DocAvailableAppointmentsState extends State wit ), ), ); + nextDayAppointmentDate = dateFormatter.format( + (isLiveCareSchedule != null && isLiveCareSchedule) + ? DateUtil.convertStringToDate(freeSlotsResponse[0]).add(Duration(days:1)) + : DateUtil.convertStringToDateSaudiTimezone( + freeSlotsResponse[0], + int.parse( + widget.doctor.projectID.toString(), + ), + ).add(Duration(days:1)), + ); DocAvailableAppointments.selectedAppoDateTime = (isLiveCareSchedule != null && isLiveCareSchedule) ? DateUtil.convertStringToDate(freeSlotsResponse[0]) : DateUtil.convertStringToDateSaudiTimezone( @@ -277,6 +329,16 @@ class _DocAvailableAppointmentsState extends State wit ), ), language); + selectedNextDate = DateUtil.getWeekDayMonthDayYearDateFormatted( + (isLiveCareSchedule != null && isLiveCareSchedule) + ? DateUtil.convertStringToDate(freeSlotsResponse[0]).add(Duration(days:1)) + : DateUtil.convertStringToDateSaudiTimezone( + freeSlotsResponse[0], + int.parse( + widget.doctor.projectID.toString(), + ), + ).add(Duration(days:1)), + language); selectedDateJSON = freeSlotsResponse[0]; }); openTimeSlotsPickerForDate( @@ -319,9 +381,21 @@ class _DocAvailableAppointmentsState extends State wit DocAvailableAppointments.selectedAppoDateTime = timeslot.end; setState(() { + selectedButtonIndex = index; + selectedNextDayButtonIndex =-1; DocAvailableAppointments.selectedTime = dayEvents[index].isoTime; print(DocAvailableAppointments.selectedTime); + DocAvailableAppointments.selectedDate = dateFormatter.format( + (isLiveCareSchedule != null && isLiveCareSchedule) + ? DateUtil.convertStringToDate(freeSlotsResponse[0]) + : DateUtil.convertStringToDateSaudiTimezone( + freeSlotsResponse[0], + int.parse( + widget.doctor.projectID.toString(), + ), + ), + ); }); projectViewModel.analytics.appointment.book_appointment_time_selection(appointment_type: 'regular', dateTime: timeslot.end, doctor: widget.doctor); }, @@ -342,12 +416,69 @@ class _DocAvailableAppointmentsState extends State wit setState(() { selectedButtonIndex = index; DocAvailableAppointments.selectedTime = dayEvents[index].isoTime; + DocAvailableAppointments.selectedDate = dateFormatter.format( + (isLiveCareSchedule != null && isLiveCareSchedule) + ? DateUtil.convertStringToDate(freeSlotsResponse[0]) + : DateUtil.convertStringToDateSaudiTimezone( + freeSlotsResponse[0], + int.parse( + widget.doctor.projectID.toString(), + ), + ), + ); print(DocAvailableAppointments.selectedTime); }); }, child: Text(dayEvents[index].isoTime!, style: TextStyle(fontSize: 12.0, color: Colors.white)), ); } + Widget getNormalNextDayButton(int index) { + return CustomTextButton( + backgroundColor: Colors.white, + elevation: 0, + side: BorderSide( + color: Colors.black, //Color of the border + style: BorderStyle.solid, //Style of the border + width: 1.5 //width of the border + ), + onPressed: () { + final timeslot = nextDayEvents[index]; + DocAvailableAppointments.selectedAppoDateTime = timeslot.end; + + setState(() { + selectedButtonIndex = -1; + selectedNextDayButtonIndex =index; + DocAvailableAppointments.selectedTime = nextDayEvents[index].isoTime; + DocAvailableAppointments.selectedDate = nextDayAppointmentDate; + print(DocAvailableAppointments.selectedTime); + }); + projectViewModel.analytics.appointment.book_appointment_time_selection(appointment_type: 'regular', dateTime: timeslot.end, doctor: widget.doctor); + }, + child: Text(nextDayEvents[index].isoTime!, style: TextStyle(fontSize: 12.0, color: Color(0xFF60686b))), + ); + } + + Widget getSelectedNextDayButton(int index) { + return CustomTextButton( + backgroundColor: nextDayEvents[index].isoTime == TranslationBase.of(context).waitingAppointment ? CustomColors.darkOrange : CustomColors.green, + elevation: 0, + side: BorderSide( + color: nextDayEvents[index].isoTime == TranslationBase.of(context).waitingAppointment ? CustomColors.darkOrange : CustomColors.green, //Color of the border + style: BorderStyle.solid, //Style of the border + width: 1.5 //width of the border + ), + onPressed: () { + setState(() { + selectedButtonIndex =-1; + selectedNextDayButtonIndex = index; + DocAvailableAppointments.selectedTime = nextDayEvents[index].isoTime; + DocAvailableAppointments.selectedDate = nextDayAppointmentDate; + print(DocAvailableAppointments.selectedTime); + }); + }, + child: Text(nextDayEvents[index].isoTime!, style: TextStyle(fontSize: 12.0, color: Colors.white)), + ); + } getDoctorFreeSlots(context, DoctorList docObject) { print(DocAvailableAppointments.initialSlotDuration);