Skip to content

Commit 2104873

Browse files
author
Shubham Jitiya
committed
feat: Fixes issue #378: ✨Added support for daily, weekly & yearly recurrence event in month view
1 parent cc99a0e commit 2104873

13 files changed

+1048
-18
lines changed

example/lib/constants.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import 'app_colors.dart';
55
class AppConstants {
66
AppConstants._();
77

8+
static final List<String> weekTitles = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
9+
810
static OutlineInputBorder inputBorder = OutlineInputBorder(
911
borderRadius: BorderRadius.circular(7),
1012
borderSide: BorderSide(

example/lib/main.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,37 @@ List<CalendarEventData> _events = [
4242
startTime: DateTime(_now.year, _now.month, _now.day, 18, 30),
4343
endTime: DateTime(_now.year, _now.month, _now.day, 22),
4444
),
45+
CalendarEventData(
46+
date: _now.subtract(Duration(days: 3)),
47+
recurrenceSettings: RecurrenceSettings.withCalculatedEndDate(
48+
startDate: _now.subtract(Duration(days: 3)),
49+
frequency: RepeatFrequency.doNotRepeat,
50+
),
51+
title: 'Leetcode Contest',
52+
description: 'Give leetcode contest',
53+
),
54+
CalendarEventData(
55+
date: _now.subtract(Duration(days: 3)),
56+
recurrenceSettings: RecurrenceSettings.withCalculatedEndDate(
57+
startDate: _now.subtract(Duration(days: 3)),
58+
frequency: RepeatFrequency.daily,
59+
recurrenceEndOn: RecurrenceEnd.after,
60+
occurrences: 5,
61+
),
62+
title: 'Physics test prep',
63+
description: 'Prepare for physics test',
64+
),
4565
CalendarEventData(
4666
date: _now.add(Duration(days: 1)),
4767
startTime: DateTime(_now.year, _now.month, _now.day, 18),
4868
endTime: DateTime(_now.year, _now.month, _now.day, 19),
69+
recurrenceSettings: RecurrenceSettings(
70+
startDate: _now,
71+
endDate: _now.add(Duration(days: 5)),
72+
frequency: RepeatFrequency.daily,
73+
recurrenceEndOn: RecurrenceEnd.after,
74+
occurrences: 5,
75+
),
4976
title: "Wedding anniversary",
5077
description: "Attend uncle's wedding anniversary.",
5178
),

example/lib/pages/event_details_page.dart

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import 'package:calendar_view/calendar_view.dart';
2+
import 'package:example/widgets/delete_event_dialog.dart';
23
import 'package:flutter/material.dart';
34

45
import '../extension.dart';
56
import 'create_event_page.dart';
67

78
class DetailsPage extends StatelessWidget {
89
final CalendarEventData event;
10+
final DateTime date;
11+
12+
const DetailsPage({
13+
required this.event,
14+
required this.date,
15+
super.key,
16+
});
917

10-
const DetailsPage({super.key, required this.event});
1118
@override
1219
Widget build(BuildContext context) {
1320
return Scaffold(
@@ -83,17 +90,15 @@ class DetailsPage extends StatelessWidget {
8390
SizedBox(
8491
height: 10.0,
8592
),
86-
Text(event.description!),
93+
Text(event.description!)
8794
],
8895
const SizedBox(height: 50),
8996
Row(
9097
children: [
9198
Expanded(
9299
child: ElevatedButton(
93-
onPressed: () {
94-
CalendarControllerProvider.of(context)
95-
.controller
96-
.remove(event);
100+
onPressed: () async {
101+
await _handleDeleteEvent(context);
97102
Navigator.of(context).pop();
98103
},
99104
child: Text('Delete Event'),
@@ -111,7 +116,7 @@ class DetailsPage extends StatelessWidget {
111116
),
112117
);
113118

114-
if (result) {
119+
if (result != null) {
115120
Navigator.of(context).pop();
116121
}
117122
},
@@ -124,4 +129,33 @@ class DetailsPage extends StatelessWidget {
124129
),
125130
);
126131
}
132+
133+
/// Handles the deletion of an event, showing a dialog for repeating events.
134+
///
135+
/// This method checks if the event is a repeating event. If it is, it shows
136+
/// a dialog to the user to choose the deletion type (e.g., delete this
137+
/// event, delete following events, delete all events).
138+
/// If the event is not repeating, it defaults to deleting all occurrences
139+
/// of the event.
140+
Future<void> _handleDeleteEvent(BuildContext context) async {
141+
DeleteEvent? result;
142+
final isRepeatingEvent = event.recurrenceSettings != null &&
143+
(event.recurrenceSettings?.frequency != RepeatFrequency.doNotRepeat);
144+
145+
if (isRepeatingEvent) {
146+
result = await showDialog(
147+
context: context,
148+
builder: (_) => DeleteEventDialog(),
149+
);
150+
} else {
151+
result = DeleteEvent.all;
152+
}
153+
if (result != null) {
154+
CalendarControllerProvider.of(context).controller.deleteRecurrenceEvent(
155+
date: date,
156+
event: event,
157+
deleteEventType: result,
158+
);
159+
}
160+
}
127161
}

0 commit comments

Comments
 (0)