|
|
|
@ -21,10 +21,11 @@ import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:table_calendar/table_calendar.dart';
|
|
|
|
|
// import 'package:table_calendar/table_calendar.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
|
|
|
|
|
|
|
|
|
class CovidTimeSlots extends StatefulWidget {
|
|
|
|
|
int projectID;
|
|
|
|
@ -100,24 +101,17 @@ class _CovidTimeSlotsState extends State<CovidTimeSlots> with TickerProviderStat
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onDaySelected(DateTime day, List events, ProjectViewModel projectViewModel) {
|
|
|
|
|
void _onDaySelected(DateTime day, ProjectViewModel projectViewModel) {
|
|
|
|
|
final DateFormat formatter = DateFormat('yyyy-MM-dd');
|
|
|
|
|
setState(() {
|
|
|
|
|
this.selectedDate = DateUtil.getWeekDayMonthDayYearDateFormatted(day, projectViewModel.isArabic ? "ar" : "en");
|
|
|
|
|
openTimeSlotsPickerForDate(day, docFreeSlots);
|
|
|
|
|
CovidTimeSlots.selectedDate = formatter.format(day);
|
|
|
|
|
_calendarController.selectedDate = day;
|
|
|
|
|
print(CovidTimeSlots.selectedDate);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onVisibleDaysChanged(DateTime first, DateTime last, CalendarFormat format) {
|
|
|
|
|
print('CALLBACK: _onVisibleDaysChanged');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onCalendarCreated(DateTime first, DateTime last, CalendarFormat format) {
|
|
|
|
|
print('CALLBACK: _onCalendarCreated');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
ProjectViewModel projectViewModel = Provider.of(context);
|
|
|
|
@ -151,6 +145,7 @@ class _CovidTimeSlotsState extends State<CovidTimeSlots> with TickerProviderStat
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
mHeight(12),
|
|
|
|
|
Card(
|
|
|
|
|
shape: cardRadius(12),
|
|
|
|
|
child: _buildTableCalendarWithBuilders(projectViewModel),
|
|
|
|
@ -165,30 +160,36 @@ class _CovidTimeSlotsState extends State<CovidTimeSlots> with TickerProviderStat
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
mHeight(8),
|
|
|
|
|
Container(
|
|
|
|
|
height: 40,
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
controller: _scrollController,
|
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
|
itemCount: dayEvents.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
return Container(
|
|
|
|
|
margin: EdgeInsets.only(right: (index == dayEvents.length - 1) ? 0 : 5.0, left: index == 0 ? 0 : 5),
|
|
|
|
|
child: ButtonTheme(
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
|
side: BorderSide(
|
|
|
|
|
color: index == selectedButtonIndex ? CustomColors.green : Colors.black, //Color of the border
|
|
|
|
|
style: BorderStyle.solid, //Style of the border
|
|
|
|
|
width: 1.5, //width of the border
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
minWidth: MediaQuery.of(context).size.width * 0.2,
|
|
|
|
|
child: index == selectedButtonIndex ? getSelectedButton(index) : getNormalButton(index)),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
CovidTimeSlots.areSlotsAvailable
|
|
|
|
|
? Container(
|
|
|
|
|
height: 40,
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
controller: _scrollController,
|
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
|
itemCount: dayEvents.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
return Container(
|
|
|
|
|
margin: EdgeInsets.only(right: (index == dayEvents.length - 1) ? 0 : 5.0, left: index == 0 ? 0 : 5),
|
|
|
|
|
child: ButtonTheme(
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
|
side: BorderSide(
|
|
|
|
|
color: index == selectedButtonIndex ? CustomColors.green : Colors.black, //Color of the border
|
|
|
|
|
style: BorderStyle.solid, //Style of the border
|
|
|
|
|
width: 1.5, //width of the border
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
minWidth: MediaQuery.of(context).size.width * 0.2,
|
|
|
|
|
child: index == selectedButtonIndex ? getSelectedButton(index) : getNormalButton(index)),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Center(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 12.0, right: 12.0),
|
|
|
|
|
child: Text(TranslationBase.of(context).noSlotsError, style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w600, letterSpacing: -0.46, color: CustomColors.grey)),
|
|
|
|
|
)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
@ -239,95 +240,35 @@ class _CovidTimeSlotsState extends State<CovidTimeSlots> with TickerProviderStat
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildTableCalendarWithBuilders(ProjectViewModel projectViewModel) {
|
|
|
|
|
return TableCalendar(
|
|
|
|
|
locale: projectViewModel.isArabic ? 'ar_SA' : 'en_US',
|
|
|
|
|
calendarController: _calendarController,
|
|
|
|
|
events: _events,
|
|
|
|
|
initialCalendarFormat: CalendarFormat.month,
|
|
|
|
|
startDay: DateTime.now(),
|
|
|
|
|
formatAnimation: FormatAnimation.slide,
|
|
|
|
|
startingDayOfWeek: StartingDayOfWeek.sunday,
|
|
|
|
|
weekendDays: [DateTime.friday, DateTime.saturday],
|
|
|
|
|
availableGestures: AvailableGestures.horizontalSwipe,
|
|
|
|
|
availableCalendarFormats: const {
|
|
|
|
|
CalendarFormat.month: '',
|
|
|
|
|
CalendarFormat.week: '',
|
|
|
|
|
},
|
|
|
|
|
calendarStyle: CalendarStyle(
|
|
|
|
|
outsideDaysVisible: false,
|
|
|
|
|
weekendStyle: TextStyle().copyWith(color: Colors.blue[800]),
|
|
|
|
|
holidayStyle: TextStyle().copyWith(color: Colors.blue[800]),
|
|
|
|
|
),
|
|
|
|
|
daysOfWeekStyle: DaysOfWeekStyle(
|
|
|
|
|
weekendStyle: TextStyle().copyWith(color: Colors.black, fontSize: 11.0, fontWeight: FontWeight.w600),
|
|
|
|
|
weekdayStyle: TextStyle().copyWith(color: Colors.black, fontSize: 11.0, fontWeight: FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
headerStyle: HeaderStyle(centerHeaderTitle: true, formatButtonVisible: false, titleTextStyle: TextStyle(fontSize: 16, letterSpacing: -0.64, fontWeight: FontWeight.w600)),
|
|
|
|
|
builders: CalendarBuilders(
|
|
|
|
|
selectedDayBuilder: (context, date, _) {
|
|
|
|
|
return FadeTransition(
|
|
|
|
|
opacity: Tween(begin: 0.0, end: 1.0).animate(_animationController),
|
|
|
|
|
child: Container(
|
|
|
|
|
margin: const EdgeInsets.all(4.0),
|
|
|
|
|
padding: const EdgeInsets.only(top: 5.0, left: 6.0),
|
|
|
|
|
color: Colors.transparent,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
|
|
|
|
child: Text(
|
|
|
|
|
'${date.day}',
|
|
|
|
|
style: TextStyle().copyWith(fontSize: 14.0),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
todayDayBuilder: (context, date, _) {
|
|
|
|
|
return Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
color: _calendarController.isSelected(date)
|
|
|
|
|
? Colors.green[400]
|
|
|
|
|
: _calendarController.isToday(date)
|
|
|
|
|
? Colors.transparent
|
|
|
|
|
: Color(0xff76cfb7),
|
|
|
|
|
),
|
|
|
|
|
width: 40.0,
|
|
|
|
|
height: 40.0,
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
'${date.day}',
|
|
|
|
|
style: TextStyle().copyWith(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 14.0,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
markersBuilder: (context, date, events, holidays) {
|
|
|
|
|
final children = <Widget>[];
|
|
|
|
|
|
|
|
|
|
if (events.isNotEmpty) {
|
|
|
|
|
children.add(
|
|
|
|
|
Positioned(
|
|
|
|
|
right: 4,
|
|
|
|
|
bottom: 4,
|
|
|
|
|
child: _buildEventsMarker(date, events),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return children;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
onDaySelected: (date, event, _) {
|
|
|
|
|
_onDaySelected(date, event, projectViewModel);
|
|
|
|
|
_animationController.forward(from: 0.0);
|
|
|
|
|
return SfCalendar(
|
|
|
|
|
controller: _calendarController,
|
|
|
|
|
minDate: DateTime.now(),
|
|
|
|
|
showNavigationArrow: true,
|
|
|
|
|
headerStyle: CalendarHeaderStyle(textAlign: TextAlign.center, textStyle: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w600, letterSpacing: -0.46)),
|
|
|
|
|
viewHeaderStyle: ViewHeaderStyle(dayTextStyle: TextStyle(fontSize: 12.0, fontWeight: FontWeight.w600, letterSpacing: -0.46, color: CustomColors.black)),
|
|
|
|
|
view: CalendarView.month,
|
|
|
|
|
todayHighlightColor: CustomColors.green,
|
|
|
|
|
selectionDecoration: containerColorRadiusBorderWidth(Colors.transparent, 4, CustomColors.green, 2.5),
|
|
|
|
|
cellBorderColor: Colors.white,
|
|
|
|
|
dataSource: MeetingDataSource(_getDataSource()),
|
|
|
|
|
monthViewSettings: const MonthViewSettings(appointmentDisplayMode: MonthAppointmentDisplayMode.indicator, showTrailingAndLeadingDates: false, appointmentDisplayCount: 1),
|
|
|
|
|
onTap: (CalendarTapDetails details) {
|
|
|
|
|
_calendarController.selectedDate = details.date;
|
|
|
|
|
_onDaySelected(details.date, projectViewModel);
|
|
|
|
|
},
|
|
|
|
|
onVisibleDaysChanged: _onVisibleDaysChanged,
|
|
|
|
|
onCalendarCreated: _onCalendarCreated,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Meeting> _getDataSource() {
|
|
|
|
|
final List<Meeting> meetings = <Meeting>[];
|
|
|
|
|
_events.forEach((key, value) {
|
|
|
|
|
final DateTime startTime = DateTime(key.year, key.month, key.day, 9, 0, 0);
|
|
|
|
|
final DateTime endTime = startTime.add(const Duration(hours: 2));
|
|
|
|
|
meetings.add(Meeting("", startTime, endTime, CustomColors.green, false));
|
|
|
|
|
});
|
|
|
|
|
return meetings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openTimeSlotsPickerForDate(DateTime dateStart, List<TimeSlot> freeSlots) {
|
|
|
|
|
dayEvents.clear();
|
|
|
|
|
DateTime dateStartObj = new DateTime(dateStart.year, dateStart.month, dateStart.day, 0, 0, 0, 0, 0);
|
|
|
|
@ -337,14 +278,12 @@ class _CovidTimeSlotsState extends State<CovidTimeSlots> with TickerProviderStat
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
if (dayEvents.length != 0)
|
|
|
|
|
if (dayEvents.length != 0) {
|
|
|
|
|
CovidTimeSlots.areSlotsAvailable = true;
|
|
|
|
|
else
|
|
|
|
|
selectedButtonIndex = 0;
|
|
|
|
|
CovidTimeSlots.selectedTime = dayEvents[selectedButtonIndex].isoTime;
|
|
|
|
|
} else
|
|
|
|
|
CovidTimeSlots.areSlotsAvailable = false;
|
|
|
|
|
|
|
|
|
|
selectedButtonIndex = 0;
|
|
|
|
|
|
|
|
|
|
CovidTimeSlots.selectedTime = dayEvents[selectedButtonIndex].isoTime;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -366,43 +305,43 @@ class _CovidTimeSlotsState extends State<CovidTimeSlots> with TickerProviderStat
|
|
|
|
|
selectedDateJSON = freeSlotsResponse[0]['FreeTimeSlots'];
|
|
|
|
|
});
|
|
|
|
|
openTimeSlotsPickerForDate(DateUtil.convertStringToDate(selectedDateJSON), docFreeSlots);
|
|
|
|
|
_calendarController.setFocusedDay(DateUtil.convertStringToDate(selectedDateJSON));
|
|
|
|
|
_calendarController.selectedDate = DateUtil.convertStringToDate(selectedDateJSON);
|
|
|
|
|
return _eventsParsed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildEventsMarker(DateTime date, List events) {
|
|
|
|
|
return Container(
|
|
|
|
|
// decoration: BoxDecoration(
|
|
|
|
|
// shape: BoxShape.circle,
|
|
|
|
|
// color: _calendarController.isSelected(date)
|
|
|
|
|
// ? Colors.green[400]
|
|
|
|
|
// : _calendarController.isToday(date)
|
|
|
|
|
// ? Colors.brown[300]
|
|
|
|
|
// : Colors.blue[400],
|
|
|
|
|
// ),
|
|
|
|
|
|
|
|
|
|
decoration: containerColorRadiusBorderWidth(
|
|
|
|
|
_calendarController.isSelected(date)
|
|
|
|
|
? CustomColors.green
|
|
|
|
|
: _calendarController.isToday(date)
|
|
|
|
|
? CustomColors.green.withOpacity(0.5)
|
|
|
|
|
: Colors.white,
|
|
|
|
|
200,
|
|
|
|
|
_calendarController.isSelected(date) ? CustomColors.green : Colors.black,
|
|
|
|
|
2),
|
|
|
|
|
width: 40.0,
|
|
|
|
|
height: 40.0,
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
'${date.day}',
|
|
|
|
|
style: TextStyle().copyWith(
|
|
|
|
|
color: _calendarController.isSelected(date) ? Colors.white : Colors.black,
|
|
|
|
|
fontSize: 13.0,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
// Widget _buildEventsMarker(DateTime date, List events) {
|
|
|
|
|
// return Container(
|
|
|
|
|
// // decoration: BoxDecoration(
|
|
|
|
|
// // shape: BoxShape.circle,
|
|
|
|
|
// // color: _calendarController.isSelected(date)
|
|
|
|
|
// // ? Colors.green[400]
|
|
|
|
|
// // : _calendarController.isToday(date)
|
|
|
|
|
// // ? Colors.brown[300]
|
|
|
|
|
// // : Colors.blue[400],
|
|
|
|
|
// // ),
|
|
|
|
|
//
|
|
|
|
|
// decoration: containerColorRadiusBorderWidth(
|
|
|
|
|
// _calendarController.isSelected(date)
|
|
|
|
|
// ? CustomColors.green
|
|
|
|
|
// : _calendarController.isToday(date)
|
|
|
|
|
// ? CustomColors.green.withOpacity(0.5)
|
|
|
|
|
// : Colors.white,
|
|
|
|
|
// 200,
|
|
|
|
|
// _calendarController.isSelected(date) ? CustomColors.green : Colors.black,
|
|
|
|
|
// 2),
|
|
|
|
|
// width: 40.0,
|
|
|
|
|
// height: 40.0,
|
|
|
|
|
// child: Center(
|
|
|
|
|
// child: Text(
|
|
|
|
|
// '${date.day}',
|
|
|
|
|
// style: TextStyle().copyWith(
|
|
|
|
|
// color: _calendarController.isSelected(date) ? Colors.white : Colors.black,
|
|
|
|
|
// fontSize: 13.0,
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Widget getNormalButton(int index) {
|
|
|
|
|
return RaisedButton(
|
|
|
|
@ -436,12 +375,16 @@ class _CovidTimeSlotsState extends State<CovidTimeSlots> with TickerProviderStat
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bookCovidTestAppointment() {
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
DoctorList docObject = new DoctorList();
|
|
|
|
|
docObject.doctorID = widget.selectedDoctorID;
|
|
|
|
|
docObject.clinicID = widget.selectedClinicID;
|
|
|
|
|
docObject.projectID = widget.projectID;
|
|
|
|
|
insertAppointmentCovidTest(context, docObject);
|
|
|
|
|
if(CovidTimeSlots.areSlotsAvailable) {
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
DoctorList docObject = new DoctorList();
|
|
|
|
|
docObject.doctorID = widget.selectedDoctorID;
|
|
|
|
|
docObject.clinicID = widget.selectedClinicID;
|
|
|
|
|
docObject.projectID = widget.projectID;
|
|
|
|
|
insertAppointmentCovidTest(context, docObject);
|
|
|
|
|
} else {
|
|
|
|
|
AppToast.showErrorToast(message: TranslationBase.of(context).selectSlot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insertAppointmentCovidTest(context, DoctorList docObject) {
|
|
|
|
@ -546,8 +489,8 @@ class _CovidTimeSlotsState extends State<CovidTimeSlots> with TickerProviderStat
|
|
|
|
|
if (res['COVID19_FreeTimeSlots'].length != 0) {
|
|
|
|
|
freeSlotsResponse = res['COVID19_FreeTimeSlots'];
|
|
|
|
|
_getJSONSlots().then((value) => {
|
|
|
|
|
setState(() => {widget.selectedClinicID = freeSlotsResponse[0]['ClinicID'], widget.selectedDoctorID = freeSlotsResponse[0]['DoctorID'], _events.clear(), _events = value})
|
|
|
|
|
});
|
|
|
|
|
setState(() => {widget.selectedClinicID = freeSlotsResponse[0]['ClinicID'], widget.selectedDoctorID = freeSlotsResponse[0]['DoctorID'], _events.clear(), _events = value})
|
|
|
|
|
});
|
|
|
|
|
} else {}
|
|
|
|
|
} else {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
@ -560,3 +503,53 @@ class _CovidTimeSlotsState extends State<CovidTimeSlots> with TickerProviderStat
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MeetingDataSource extends CalendarDataSource {
|
|
|
|
|
MeetingDataSource(List<Meeting> source) {
|
|
|
|
|
appointments = source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
DateTime getStartTime(int index) {
|
|
|
|
|
return _getMeetingData(index).from;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
DateTime getEndTime(int index) {
|
|
|
|
|
return _getMeetingData(index).to;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String getSubject(int index) {
|
|
|
|
|
return _getMeetingData(index).eventName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Color getColor(int index) {
|
|
|
|
|
return _getMeetingData(index).background;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
bool isAllDay(int index) {
|
|
|
|
|
return _getMeetingData(index).isAllDay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Meeting _getMeetingData(int index) {
|
|
|
|
|
final dynamic meeting = appointments[index];
|
|
|
|
|
Meeting meetingData;
|
|
|
|
|
if (meeting is Meeting) {
|
|
|
|
|
meetingData = meeting;
|
|
|
|
|
}
|
|
|
|
|
return meetingData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Meeting {
|
|
|
|
|
Meeting(this.eventName, this.from, this.to, this.background, this.isAllDay);
|
|
|
|
|
|
|
|
|
|
String eventName;
|
|
|
|
|
DateTime from;
|
|
|
|
|
DateTime to;
|
|
|
|
|
Color background;
|
|
|
|
|
bool isAllDay;
|
|
|
|
|
}
|
|
|
|
|