calender reminder added

calender_reminder
tahaalam 2 months ago
parent 9ca0a985a3
commit fc0f98da1d

File diff suppressed because one or more lines are too long

@ -0,0 +1,94 @@
import 'dart:async';
import 'package:device_calendar_plus/device_calendar_plus.dart';
import 'package:jiffy/jiffy.dart' show Jiffy;
class CalenderUtilsNew {
final DeviceCalendar calender = DeviceCalendar.instance;
List<Calendar> writableCalender = [];
CalenderUtilsNew._instance() {
getCalenders();
}
static final CalenderUtilsNew instance = CalenderUtilsNew._instance();
Future<void> getCalenders() async {
CalendarPermissionStatus result = await DeviceCalendar.instance.hasPermissions();
if(result != CalendarPermissionStatus.granted) await DeviceCalendar.instance.requestPermissions();
var calenders = await calender.listCalendars();
calenders.forEach((calender) {
if (!calender.readOnly) {
writableCalender.add(calender);
}
});
}
FutureOr<bool> createOrUpdateEvent({required String title, required String description, required String location, DateTime? scheduleDateTime, String? eventId, int? reminderMinutes}) async {
print("the reminder minutes are $reminderMinutes");
if (writableCalender.isEmpty) {
await getCalenders();
}
var writableCalendars = writableCalender.first;
print("writableCalendars-name: " + writableCalendars.name);
print("writableCalendars-Id: " + writableCalendars.id);
print("writableCalendarsToString: " + writableCalendars.toString());
print("writableCalendarsToString: " + writableCalendars!.id!);
CalendarPermissionStatus result = await DeviceCalendar.instance.hasPermissions();
if(result != CalendarPermissionStatus.granted) await DeviceCalendar.instance.requestPermissions();
print(result);
String eventResult = await DeviceCalendar.instance.createEvent(
calendarId: writableCalendars!.id,
title: title,
description: description,
startDate: scheduleDateTime!,
endDate: scheduleDateTime!.add(Duration(minutes: 30)),
reminderMinutes: reminderMinutes
);
print("the event Result is ${eventResult}");
return eventResult.isNotEmpty;
}
FutureOr<List<Event>> getEvents() async {
var availableCalender = writableCalender.first;
DateTime startEventsDate = Jiffy.parseFromDateTime(DateTime.now()).subtract(days: 30).dateTime;
DateTime endEventsDate = Jiffy.parseFromDateTime(DateTime.now()).add(days: 120).dateTime;
return await calender.listEvents(startEventsDate, endEventsDate, calendarIds: [availableCalender.id]);
}
FutureOr<bool> checkIfEventExist(String admissionId) async {
if(writableCalender.isEmpty)return false;
List<Event> events = await getEvents();
if(events.isEmpty) return false;
for(var event in events){
List<String> title = event.title!.split("#");
print("the splitted admission id is ${title}");
if(title.contains(admissionId)) return true;
}
return false;
}
FutureOr<bool> checkAndRemove({required String id}) async {
if(writableCalender.isEmpty)return false;
List<Event> events = await getEvents();
if(events.isEmpty) return false;
for(var event in events){
List<String> title = event.title!.split("#");
print("the splitted admission id is ${title}");
if(title.contains(id)) {
calender.deleteEvent(eventId: event.eventId);
return true;
}
}
return false;
}
}

@ -17,8 +17,7 @@ class DateUtil {
final endIndex = date.indexOf(end, startIndex + start.length);
return DateTime.fromMillisecondsSinceEpoch(int.parse(
date.substring(startIndex + start.length, endIndex),
))
;
));
}
static DateTime convertStringToDateSaudiTimezone(String date, int projectId) {

@ -1,10 +1,16 @@
import 'dart:async';
import 'dart:collection';
import 'dart:io';
import 'package:device_calendar/device_calendar.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/core/utils/calendar_utils.dart';
import 'package:hmg_patient_app_new/core/utils/calender_utils_new.dart';
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
@ -62,11 +68,13 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
@override
void initState() {
scheduleMicrotask(() {
// if (AppointmentType.isArrived(widget.patientAppointmentHistoryResponseModel)) {
// prescriptionsViewModel.setPrescriptionsDetailsLoading();
// prescriptionsViewModel.getPrescriptionDetails(getPrescriptionRequestModel());
// }
scheduleMicrotask(() async {
CalenderUtilsNew calendarUtils = await CalenderUtilsNew.instance;
var doesExist = await calendarUtils.checkIfEventExist("${widget.patientAppointmentHistoryResponseModel.appointmentNo}");
print("the appointment reminder exist $doesExist");
myAppointmentsViewModel.setAppointmentReminder(doesExist, widget.patientAppointmentHistoryResponseModel);
});
super.initState();
}
@ -272,10 +280,54 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
// activeThumbColor: AppColors.successColor,
activeTrackColor: AppColors.successColor.withValues(alpha: .15),
value: widget.patientAppointmentHistoryResponseModel.hasReminder!,
onChanged: (newValue) {
setState(() {
myAppointmentsViewModel.setAppointmentReminder(newValue, widget.patientAppointmentHistoryResponseModel);
});
onChanged: (newValue) async {
CalenderUtilsNew calender = CalenderUtilsNew.instance;
bool isEventAddedOrRemoved = false;
if(newValue == true){
DateTime startDate = DateTime.now();
DateTime endDate = DateUtil.convertStringToDate(widget
.patientAppointmentHistoryResponseModel.appointmentDate);
showReminderBottomSheet(
context,
endDate,
widget.patientAppointmentHistoryResponseModel.doctorNameObj??"",
"${widget.patientAppointmentHistoryResponseModel.appointmentNo}"??"",
"",
"",
title: "Appointment with ${widget.patientAppointmentHistoryResponseModel.doctorNameObj}".needTranslation,
description:"${widget.patientAppointmentHistoryResponseModel.doctorNameObj} will be having an appointment on ${widget.patientAppointmentHistoryResponseModel.appointmentDate}".needTranslation,
onSuccess: () {
setState(() {
myAppointmentsViewModel.setAppointmentReminder(newValue, widget.patientAppointmentHistoryResponseModel);
});
},
isMultiAllowed: true,
onMultiDateSuccess: (int selectedIndex) async {
isEventAddedOrRemoved = await calender.createOrUpdateEvent(
title: "Appointment Reminder with ${widget.patientAppointmentHistoryResponseModel.doctorNameObj} on ${DateUtil.convertStringToDate(widget
.patientAppointmentHistoryResponseModel.appointmentDate)}, Appointment #${widget.patientAppointmentHistoryResponseModel.appointmentNo}".needTranslation,
description: "Appointment Reminder with ${widget.patientAppointmentHistoryResponseModel.doctorNameObj} in ${widget
.patientAppointmentHistoryResponseModel.projectName}",
scheduleDateTime: DateUtil.convertStringToDate(widget
.patientAppointmentHistoryResponseModel.appointmentDate),
eventId: "${widget.patientAppointmentHistoryResponseModel.appointmentNo}",
location: '',
reminderMinutes: selectedIndex
);
setState(() {
myAppointmentsViewModel.setAppointmentReminder(isEventAddedOrRemoved, widget.patientAppointmentHistoryResponseModel);
});
},
);
}else {
isEventAddedOrRemoved = await calender.checkAndRemove( id:"${widget.patientAppointmentHistoryResponseModel.appointmentNo}", );
setState(() {
myAppointmentsViewModel.setAppointmentReminder(isEventAddedOrRemoved, widget.patientAppointmentHistoryResponseModel);
});
}
},
),
],

@ -100,7 +100,7 @@ class _PrescriptionReminderViewState extends State<PrescriptionReminderView> {
text: LocaleKeys.setReminder.tr(),
onPressed: () {
Navigator.of(context).pop();
widget.setReminder(_selectedOption);
widget.setReminder(_options[_selectedOption]);
},
backgroundColor: AppColors.bgGreenColor,
borderColor: AppColors.bgGreenColor,

@ -45,6 +45,7 @@ dependencies:
file_picker: ^10.3.2
local_auth: ^2.3.0
share_plus: ^11.1.0
device_calendar_plus: ^0.3.1
device_calendar:
git: https://github.com/bardram/device_calendar
manage_calendar_events: ^2.0.3

Loading…
Cancel
Save