From e1e3741abf7d9514185f45df11f30b0b3bbc1bcf Mon Sep 17 00:00:00 2001 From: "Mirza.Shafique" Date: Wed, 1 Sep 2021 16:28:56 +0300 Subject: [PATCH] Event Reminder --- lib/config/config.dart | 4 +- lib/pages/BookAppointment/DoctorProfile.dart | 14 +++- .../BookAppointment/book_reminder_page.dart | 69 ++++------------ .../widgets/reminder_dialog.dart | 81 +++++++++++++++++++ .../widgets/AppointmentActions.dart | 75 ++++++++++------- lib/uitl/CalendarUtils.dart | 11 ++- 6 files changed, 163 insertions(+), 91 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index 7152cbbe..45c31e14 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -13,8 +13,8 @@ const PACKAGES_CUSTOMER = '/api/customers'; const PACKAGES_SHOPPING_CART = '/api/shopping_cart_items'; const PACKAGES_ORDERS = '/api/orders'; -const BASE_URL = 'https://uat.hmgwebservices.com/'; -// const BASE_URL = 'https://hmgwebservices.com/'; +// const BASE_URL = 'https://uat.hmgwebservices.com/'; +const BASE_URL = 'https://hmgwebservices.com/'; // Pharmacy UAT URLs const BASE_PHARMACY_URL = 'https://uat.hmgwebservices.com/epharmacy/api/'; diff --git a/lib/pages/BookAppointment/DoctorProfile.dart b/lib/pages/BookAppointment/DoctorProfile.dart index 88cf53e6..ac423343 100644 --- a/lib/pages/BookAppointment/DoctorProfile.dart +++ b/lib/pages/BookAppointment/DoctorProfile.dart @@ -488,9 +488,15 @@ class _DoctorProfileState extends State with TickerProviderStateM Future navigateToBookConfirm(context) async { Navigator.push( - context, - FadePage( - page: BookConfirm( - doctor: widget.doctor, isLiveCareAppointment: widget.isLiveCareAppointment, selectedDate: DocAvailableAppointments.selectedDate, selectedTime: DocAvailableAppointments.selectedTime))); + context, + FadePage( + page: BookConfirm( + doctor: widget.doctor, + isLiveCareAppointment: widget.isLiveCareAppointment, + selectedDate: DocAvailableAppointments.selectedDate, + selectedTime: DocAvailableAppointments.selectedTime, + ), + ), + ); } } diff --git a/lib/pages/BookAppointment/book_reminder_page.dart b/lib/pages/BookAppointment/book_reminder_page.dart index fc5c96e8..2e649ab8 100644 --- a/lib/pages/BookAppointment/book_reminder_page.dart +++ b/lib/pages/BookAppointment/book_reminder_page.dart @@ -52,13 +52,13 @@ class _BookReminderPageState extends State { isSuccessShow = false; }); }); + } @override Widget build(BuildContext context) { // print("selectedTime "+selectedTime??""); - print("appoDateFormatted " + widget.appoDateFormatted ?? ""); - print("appoTimeFormatted " + widget.appoTimeFormatted ?? ""); + print("appointmentNo1 " + widget.patientShareResponse.appointmentNo.toString() ?? ""); return AppScaffold( appBarTitle: widget.docObject.doctorTitle + " " + widget.docObject.name, isShowDecPage: false, @@ -194,15 +194,19 @@ class _BookReminderPageState extends State { disabledTextColor: Colors.white, disabledColor: CustomColors.green, onPressed: () async { - if (await Permission.contacts.request().isGranted) { - _showReminderDialog(context); - } else { - requestPermissions().then((results) { - if (results[Permission.calendar].isGranted) { - _showReminderDialog(context); - } - }); - } + print(widget.patientShareResponse.appointmentNo); + showReminderDialog( + context, + widget.dateTime, + widget.docObject.name, + widget.patientShareResponse.appointmentNo.toString(), + widget.appoDateFormatted, + widget.appoTimeFormatted, + onSuccess: () { + AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess); + navigateToBookSuccess(context); + }, + ); }, child: Text(TranslationBase.of(context).yes, style: TextStyle(fontSize: 16.0, letterSpacing: -0.48)), ), @@ -223,49 +227,6 @@ class _BookReminderPageState extends State { BookSuccess(docObject: widget.docObject, patientShareResponse: widget.patientShareResponse, appoDateFormatted: widget.appoDateFormatted, appoTimeFormatted: widget.appoTimeFormatted))); } - Future _showReminderDialog(BuildContext context) async { - return showDialog( - context: context, - barrierDismissible: true, // user must tap button! - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)), //this right here - child: ReminderDialog( - onClick: (int i) async { - if (i == 0) { - // Before 30 mints - widget.dateTime = Jiffy(widget.dateTime).subtract(minutes: 30); - // dateTime.add(new Duration(minutes: -30)); - } else if (i == 1) { - // Before 1 hour - // dateTime.add(new Duration(minutes: -60)); - widget.dateTime = Jiffy(widget.dateTime).subtract(hours: 1); - } else if (i == 2) { - // Before 1 hour and 30 mints - // dateTime.add(new Duration(minutes: -90)); - widget.dateTime = Jiffy(widget.dateTime).subtract(hours: 1, minutes: 30); - } else if (i == 3) { - // Before 2 hours - // dateTime.add(new Duration(minutes: -120)); - widget.dateTime = Jiffy(widget.dateTime).subtract(hours: 2); - } - CalendarUtils calendarUtils = await CalendarUtils.getInstance(); - calendarUtils - .createOrUpdateEvent( - title: TranslationBase.of(context).reminderTitle + " " + widget.docObject.name, - description: "At " + widget.appoDateFormatted + " " + widget.appoTimeFormatted, - scheduleDateTime: widget.dateTime) - .then((value) { - AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess); - navigateToBookSuccess(context); - }); - }, - ), - ); - }, - ); - } - Future> requestPermissions() async { var permissionResults = [Permission.calendar].request(); return permissionResults; diff --git a/lib/pages/BookAppointment/widgets/reminder_dialog.dart b/lib/pages/BookAppointment/widgets/reminder_dialog.dart index 5aec2d74..f0ba3091 100644 --- a/lib/pages/BookAppointment/widgets/reminder_dialog.dart +++ b/lib/pages/BookAppointment/widgets/reminder_dialog.dart @@ -1,6 +1,87 @@ import 'package:diplomaticquarterapp/theme/colors.dart'; +import 'package:diplomaticquarterapp/uitl/CalendarUtils.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils_new.dart'; import 'package:flutter/material.dart'; +import 'package:jiffy/jiffy.dart'; +import 'package:manage_calendar_events/manage_calendar_events.dart'; +import 'package:permission_handler/permission_handler.dart'; + +Future> requestPermissions() async { + var permissionResults = [Permission.calendar].request(); + return permissionResults; +} + +showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted, {Function onSuccess}) async { + if (await Permission.calendar.request().isGranted) { + _showReminderDialog( + context, + dateTime, + doctorName, + eventId, + appoDateFormatted, + appoTimeFormatted, + onSuccess: onSuccess, + ); + } else { + requestPermissions().then((results) { + if (results[Permission.calendar].isGranted) { + _showReminderDialog( + context, + dateTime, + doctorName, + eventId, + appoDateFormatted, + appoTimeFormatted, + onSuccess: onSuccess, + ); + } + }); + } +} + +final CalendarPlugin _myPlugin = CalendarPlugin(); + +Future _showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted, {Function onSuccess}) async { + return showDialog( + context: context, + barrierDismissible: true, // user must tap button! + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)), //this right here + child: ReminderDialog( + onClick: (int i) async { + if (i == 0) { + // Before 30 mints + dateTime = Jiffy(dateTime).subtract(minutes: 30); + // dateTime.add(new Duration(minutes: -30)); + } else if (i == 1) { + // Before 1 hour + // dateTime.add(new Duration(minutes: -60)); + dateTime = Jiffy(dateTime).subtract(hours: 1); + } else if (i == 2) { + // Before 1 hour and 30 mints + // dateTime.add(new Duration(minutes: -90)); + dateTime = Jiffy(dateTime).subtract(hours: 1, minutes: 30); + } else if (i == 3) { + // Before 2 hours + // dateTime.add(new Duration(minutes: -120)); + dateTime = Jiffy(dateTime).subtract(hours: 2); + } + CalendarUtils calendarUtils = await CalendarUtils.getInstance(); + calendarUtils + .createOrUpdateEvent( + title: TranslationBase.of(context).reminderTitle + " " + doctorName, description: "At " + appoDateFormatted + " " + appoTimeFormatted, scheduleDateTime: dateTime, eventId: eventId) + .then((value) {}); + + onSuccess(); + }, + ), + ); + }, + ); +} class ReminderDialog extends StatefulWidget { Function onClick; diff --git a/lib/pages/MyAppointments/widgets/AppointmentActions.dart b/lib/pages/MyAppointments/widgets/AppointmentActions.dart index 9fcff311..6fd63f56 100644 --- a/lib/pages/MyAppointments/widgets/AppointmentActions.dart +++ b/lib/pages/MyAppointments/widgets/AppointmentActions.dart @@ -6,7 +6,8 @@ import 'package:diplomaticquarterapp/core/viewModels/feedback/feedback_view_mode import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; import 'package:diplomaticquarterapp/models/Appointments/appoDetailsButtons.dart'; -import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart'; +import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/reminder_dialog.dart'; + import 'package:diplomaticquarterapp/pages/MyAppointments/models/AppointmentType.dart'; import 'package:diplomaticquarterapp/pages/MyAppointments/models/ArrivedButtons.dart'; import 'package:diplomaticquarterapp/pages/MyAppointments/models/AskDocRequestTypeModel.dart'; @@ -17,6 +18,7 @@ import 'package:diplomaticquarterapp/pages/MyAppointments/models/ConfirmedButton import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/PrescriptionReport.dart'; import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/askDocDialog.dart'; import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/reminder_dialog.dart'; + import 'package:diplomaticquarterapp/pages/feedback/feedback_home_page.dart'; import 'package:diplomaticquarterapp/pages/insurance/insurance_approval_screen.dart'; import 'package:diplomaticquarterapp/pages/medical/labs/laboratory_result_page.dart'; @@ -24,7 +26,9 @@ import 'package:diplomaticquarterapp/pages/medical/radiology/radiology_details_p import 'package:diplomaticquarterapp/pages/medical/vital_sign/vital_sign_details_screen.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart'; +import 'package:diplomaticquarterapp/uitl/CalendarUtils.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/data_display/medical/medical_profile_item.dart'; @@ -153,7 +157,6 @@ class _AppointmentActionsState extends State { } _handleButtonClicks(AppoDetailsButton) { - switch (AppoDetailsButton.caller) { case "openReschedule": widget.tabController.animateTo((widget.tabController.index + 1) % 2); @@ -182,7 +185,18 @@ class _AppointmentActionsState extends State { break; case "addReminder": - showReminderDialog(widget.appo); + // showReminderDialog(widget.appo); + showReminderDialog( + context, + DateUtil.convertStringToDate(widget.appo.appointmentDate), + widget.appo.doctorNameObj, + "", + DateUtil.formatDateToDate(DateUtil.convertStringToDate(widget.appo.appointmentDate)), + DateUtil.formatDateToTime(DateUtil.convertStringToDate(widget.appo.appointmentDate)), + onSuccess: () { + AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess); + }, + ); break; case "goToTodoList": @@ -502,32 +516,35 @@ class _AppointmentActionsState extends State { } } - showReminderDialog(AppoitmentAllHistoryResultList appo) { - showGeneralDialog( - barrierColor: Colors.black.withOpacity(0.5), - transitionBuilder: (context, a1, a2, widget) { - final curvedValue = Curves.easeInOutBack.transform(a1.value) - 1.0; - return Transform( - transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0), - child: Opacity( - opacity: a1.value, - child: ReminderDialog( - eventId: appo.appointmentNo.toString(), - title: "Doctor Appointment", - description: "You have an appointment with " + appo.doctorTitle + " " + appo.doctorNameObj, - startDate: appo.appointmentDate, - endDate: appo.appointmentDate, - location: appo.projectName, - ), - ), - ); - }, - transitionDuration: Duration(milliseconds: 500), - barrierDismissible: true, - barrierLabel: '', - context: context, - pageBuilder: (context, animation1, animation2) {}); - } + // showReminderDialog(AppoitmentAllHistoryResultList appo) { + // + // + // //old reminder dialog having location + // showGeneralDialog( + // barrierColor: Colors.black.withOpacity(0.5), + // transitionBuilder: (context, a1, a2, widget) { + // final curvedValue = Curves.easeInOutBack.transform(a1.value) - 1.0; + // return Transform( + // transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0), + // child: Opacity( + // opacity: a1.value, + // child: ReminderDialog( + // eventId: appo.appointmentNo.toString(), + // title: "Doctor Appointment", + // description: "You have an appointment with " + appo.doctorTitle + " " + appo.doctorNameObj, + // startDate: appo.appointmentDate, + // endDate: appo.appointmentDate, + // location: appo.projectName, + // ), + // ), + // ); + // }, + // transitionDuration: Duration(milliseconds: 500), + // barrierDismissible: true, + // barrierLabel: '', + // context: context, + // pageBuilder: (context, animation1, animation2) {}); + // } askYourDoc() { GifLoaderDialogUtils.showMyDialog(context); diff --git a/lib/uitl/CalendarUtils.dart b/lib/uitl/CalendarUtils.dart index b1489d2b..0ab8be19 100644 --- a/lib/uitl/CalendarUtils.dart +++ b/lib/uitl/CalendarUtils.dart @@ -46,14 +46,19 @@ class CalendarUtils { }); } - Future createOrUpdateEvent({ String title, String description, DateTime scheduleDateTime}) async { + Future createOrUpdateEvent({ String title, String description, DateTime scheduleDateTime,String eventId}) async { RecurrenceRule recurrenceRule = RecurrenceRule( RecurrenceFrequency.Daily, // daysOfWeek: daysOfWeek, endDate: scheduleDateTime, ); + print("eventId "+eventId); Event event = Event(writableCalendars.id, recurrenceRule: recurrenceRule, start: scheduleDateTime, end: scheduleDateTime.add(Duration(minutes: 30)), title: title, description: description); - deviceCalendarPlugin.createOrUpdateEvent(event); + deviceCalendarPlugin.createOrUpdateEvent(event).catchError((e){ + print("catchError "+e.toString()); + }).whenComplete(() { + print("whenComplete "+eventId); + }); } deleteEvent(Calendar _calendar, Event _event) async { @@ -67,6 +72,8 @@ class CalendarUtils { return await deviceCalendarPlugin.retrieveEvents(calendarId, retrieveEventsParams); } + + Future createCalendar( String calendarName, { Color calendarColor,