Skip to content

Commit caa67ee

Browse files
author
Shubham Jitiya
committed
feat: Fixes issue #378: ✨ Add support for single day & full day recurring events
1 parent 836953e commit caa67ee

14 files changed

+1073
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Fixes right icon always shows default icon in `CalendarPageHeader` when providing custom icon. [#432](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/432)
66
- Adds `hideDaysNotInMonth` argument in `cellBuilder` in readme. [#433](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/433)
77
- Fixes `titleColor` of date for `hideDaysNotInMonth: false`.
8+
- Adds support for single day & full day recurring events. [#378](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/378)
89

910
# [1.3.0 - 12 Nov 2024](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.3.0)
1011

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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,36 @@ 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+
),
50+
title: 'Leetcode Contest',
51+
description: 'Give leetcode contest',
52+
),
53+
CalendarEventData(
54+
date: _now.subtract(Duration(days: 3)),
55+
recurrenceSettings: RecurrenceSettings.withCalculatedEndDate(
56+
startDate: _now.subtract(Duration(days: 3)),
57+
frequency: RepeatFrequency.daily,
58+
recurrenceEndOn: RecurrenceEnd.after,
59+
occurrences: 5,
60+
),
61+
title: 'Physics test prep',
62+
description: 'Prepare for physics test',
63+
),
4564
CalendarEventData(
4665
date: _now.add(Duration(days: 1)),
4766
startTime: DateTime(_now.year, _now.month, _now.day, 18),
4867
endTime: DateTime(_now.year, _now.month, _now.day, 19),
68+
recurrenceSettings: RecurrenceSettings(
69+
startDate: _now,
70+
endDate: _now.add(Duration(days: 5)),
71+
frequency: RepeatFrequency.daily,
72+
recurrenceEndOn: RecurrenceEnd.after,
73+
occurrences: 5,
74+
),
4975
title: "Wedding anniversary",
5076
description: "Attend uncle's wedding anniversary.",
5177
),

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)