fetchWeekEvents method

Future<List<CalendarMonthEvent>> fetchWeekEvents({
  1. String? templateId,
  2. required DateTime displayDate,
  3. required bool parentElementsOnly,
})

Implementation

Future<List<CalendarMonthEvent>> fetchWeekEvents({
  String? templateId,
  required DateTime displayDate,
  required bool parentElementsOnly,
}) async {
  final allMonthEvents = await fetchMonthEvents(
    templateId: templateId,
    displayDate: displayDate,
    parentElementsOnly: parentElementsOnly,
  );

  // Filter events for the specific week
  final startOfWeek = displayDate.subtract(Duration(
      days: displayDate.weekday -
          1)); // Assuming Monday is the first day of the week
  final endOfWeek = startOfWeek.add(const Duration(days: 7));

  return allMonthEvents.where((event) {
    return event.startDate.isBefore(endOfWeek) &&
        event.endDate.isAfter(startOfWeek);
  }).toList();
}