Calender Event Fixes

dev_v3.13.6_BLE_Faiz
Aamir.Muhammad 1 year ago
parent 2e25940b62
commit 0ef716f536

@ -1,4 +1,5 @@
import 'dart:collection';
import 'dart:io';
import 'package:device_calendar/device_calendar.dart';
import 'package:diplomaticquarterapp/core/model/prescriptions/Prescriptions.dart';
@ -254,6 +255,48 @@ class _PrescriptionDetailsPageState extends State<PrescriptionDetailsPage> {
if (calendarUtils.calendars != null) {
print(calendarUtils.calendars);
if (Platform.isAndroid) {
Future.forEach(
calendarUtils.calendars,
(Calendar calender) => {
calendarUtils.retrieveEvents(calender.id!, params).then((value) {
Result<UnmodifiableListView<Event>> events = value;
events.data!.forEach((element) {
print(widget.prescriptionReport!.itemDescriptionN!);
if (element.title!.contains(widget.prescriptionReport!.itemDescriptionN!))
setState(() {
hasReminder = true;
});
});
}),
});
} else {
Future.forEach(
calendarUtils.calendars,
(List<Calendar> calender) => {
calendarUtils.retrieveEvents(calender[0].id!, params).then((value) {
Result<UnmodifiableListView<Event>> events = value;
events.data!.forEach((element) {
print(widget.prescriptionReport!.itemDescriptionN!);
if (element.title!.contains(widget.prescriptionReport!.itemDescriptionN!))
setState(() {
hasReminder = true;
});
});
}),
});
}
}
}
cancelReminders() async {
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
DateTime startEventsDate = Jiffy.parseFromDateTime(DateTime.now()).subtract(days: 30).dateTime;
DateTime endEventsDate = Jiffy.parseFromDateTime(DateTime.now()).add(days: 120).dateTime;
RetrieveEventsParams params = RetrieveEventsParams(startDate: startEventsDate, endDate: endEventsDate);
if (Platform.isAndroid) {
Future.forEach(
calendarUtils.calendars,
(Calendar calender) => {
@ -261,35 +304,23 @@ class _PrescriptionDetailsPageState extends State<PrescriptionDetailsPage> {
Result<UnmodifiableListView<Event>> events = value;
events.data!.forEach((element) {
print(widget.prescriptionReport!.itemDescriptionN!);
if (element.title!.contains(widget.prescriptionReport!.itemDescriptionN!))
setState(() {
hasReminder = true;
});
if (element.title!.contains(widget.prescriptionReport!.itemDescriptionN!)) calendarUtils.deleteEvent(calender, element);
});
}),
});
} else {
Future.forEach(
calendarUtils.calendars,
(List<Calendar> calender) => {
calendarUtils.retrieveEvents(calender[0].id!, params).then((value) {
Result<UnmodifiableListView<Event>> events = value;
events.data!.forEach((element) {
print(widget.prescriptionReport!.itemDescriptionN!);
if (element.title!.contains(widget.prescriptionReport!.itemDescriptionN!)) calendarUtils.deleteEvent(calender, element);
});
}),
});
}
}
cancelReminders() async {
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
DateTime startEventsDate = Jiffy.parseFromDateTime(DateTime.now()).subtract(days: 30).dateTime;
DateTime endEventsDate = Jiffy.parseFromDateTime(DateTime.now()).add(days: 120).dateTime;
RetrieveEventsParams params = RetrieveEventsParams(startDate: startEventsDate, endDate: endEventsDate);
Future.forEach(
calendarUtils.calendars,
(Calendar calender) => {
calendarUtils.retrieveEvents(calender.id!, params).then((value) {
Result<UnmodifiableListView<Event>> events = value;
events.data!.forEach((element) {
print(widget.prescriptionReport!.itemDescriptionN!);
if (element.title!.contains(widget.prescriptionReport!.itemDescriptionN!)) calendarUtils.deleteEvent(calender, element);
});
}),
});
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderCancelSuccess);
setState(() {
hasReminder = false;

Loading…
Cancel
Save