Skip to content

Commit

Permalink
🔨 Added delete specific event
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-jitiya-simform committed Nov 8, 2024
1 parent b7d072a commit 51a1bcb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
15 changes: 13 additions & 2 deletions example/lib/pages/event_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,19 @@ class DetailsPage extends StatelessWidget {
Expanded(
child: ElevatedButton(
onPressed: () {
final updatedRecurrenceSettings =
event.recurrenceSettings?.copyWith(endDate: date);
// Delete following events
// final updatedRecurrenceSettings =
// event.recurrenceSettings?.copyWith(endDate: date);
// final updatedEvent = event.copyWith(
// recurrenceSettings: updatedRecurrenceSettings);
// CalendarControllerProvider.of(context)
// .controller
// .update(event, updatedEvent);
List<DateTime> excludeDates =
event.recurrenceSettings?.excludeDates ?? [];
excludeDates.add(date);
final updatedRecurrenceSettings = event.recurrenceSettings
?.copyWith(excludeDates: excludeDates);
final updatedEvent = event.copyWith(
recurrenceSettings: updatedRecurrenceSettings);
CalendarControllerProvider.of(context)
Expand Down
9 changes: 7 additions & 2 deletions lib/src/event_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,21 @@ class EventController<T extends Object?> extends ChangeNotifier {
continue;
}
final recurrenceSettings = event.recurrenceSettings;
if (recurrenceSettings == null) {
debugPrint('Date: ${date} | Recurrence settings: ${recurrenceSettings}');
// if event is not repeating or date is in excluded
if (recurrenceSettings == null ||
(recurrenceSettings.excludeDates?.contains(date) ?? false)) {
continue;
}

debugPrint(
'Date: ${date} | Is excluded dates: ${recurrenceSettings.excludeDates}');
final isRecurrence = _handleRecurrence(
currentDate: date,
eventStartDate: event.date,
eventEndDate: event.endDate,
recurrenceSettings: recurrenceSettings,
);
debugPrint('Is recurrence: ${isRecurrence}');
if (isRecurrence) {
events.add(event);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/src/modals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ class RecurrenceSettings {
final RepeatFrequency frequency;
final RecurrenceEnd recurrenceEndOn;
final List<int> weekdays;
final List<DateTime>? excludeDates;

RecurrenceSettings({
required this.startDate,
this.endDate,
this.interval,
this.frequency = RepeatFrequency.weekly,
this.recurrenceEndOn = RecurrenceEnd.never,
this.excludeDates,
List<int>? weekdays,
}) : weekdays = weekdays ?? [startDate.weekday];

Expand All @@ -116,7 +118,8 @@ class RecurrenceSettings {
"interval: ${interval}, "
"frequency: ${frequency} "
"weekdays: ${weekdays.toString()}"
"recurrence Ends on: ${recurrenceEndOn}";
"recurrence Ends on: ${recurrenceEndOn}"
"exclude dates: ${excludeDates}";
}

RecurrenceSettings copyWith({
Expand All @@ -126,6 +129,7 @@ class RecurrenceSettings {
RepeatFrequency? frequency,
RecurrenceEnd? recurrenceEndOn,
List<int>? weekdays,
List<DateTime>? excludeDates,
}) {
return RecurrenceSettings(
startDate: startDate ?? this.startDate,
Expand All @@ -134,6 +138,7 @@ class RecurrenceSettings {
frequency: frequency ?? this.frequency,
recurrenceEndOn: recurrenceEndOn ?? this.recurrenceEndOn,
weekdays: weekdays ?? this.weekdays,
excludeDates: excludeDates ?? this.excludeDates,
);
}
}

0 comments on commit 51a1bcb

Please sign in to comment.