Skip to content

Commit

Permalink
feat: Fixes issue #378: ✨Added support for daily & weekly recurrence …
Browse files Browse the repository at this point in the history
…event in month view
  • Loading branch information
shubham-jitiya-simform committed Nov 19, 2024
1 parent cc99a0e commit 790b419
Show file tree
Hide file tree
Showing 13 changed files with 876 additions and 13 deletions.
2 changes: 2 additions & 0 deletions example/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'app_colors.dart';
class AppConstants {
AppConstants._();

static final List<String> weekTitles = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];

static OutlineInputBorder inputBorder = OutlineInputBorder(
borderRadius: BorderRadius.circular(7),
borderSide: BorderSide(
Expand Down
19 changes: 19 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,29 @@ List<CalendarEventData> _events = [
startTime: DateTime(_now.year, _now.month, _now.day, 18, 30),
endTime: DateTime(_now.year, _now.month, _now.day, 22),
),
CalendarEventData(
date: _now.subtract(Duration(days: 3)),
recurrenceSettings: RecurrenceSettings.withCalculatedEndDate(
startDate: _now.subtract(Duration(days: 3)),
endDate: _now.subtract(Duration(days: 3)),
frequency: RepeatFrequency.daily,
recurrenceEndOn: RecurrenceEnd.after,
interval: 5,
),
title: "Physics test prep",
description: "Prepare for physics test",
),
CalendarEventData(
date: _now.add(Duration(days: 1)),
startTime: DateTime(_now.year, _now.month, _now.day, 18),
endTime: DateTime(_now.year, _now.month, _now.day, 19),
recurrenceSettings: RecurrenceSettings(
startDate: _now,
endDate: _now.add(Duration(days: 5)),
frequency: RepeatFrequency.daily,
interval: 5,
recurrenceEndOn: RecurrenceEnd.after,
),
title: "Wedding anniversary",
description: "Attend uncle's wedding anniversary.",
),
Expand Down
46 changes: 40 additions & 6 deletions example/lib/pages/event_details_page.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import 'package:calendar_view/calendar_view.dart';
import 'package:example/pages/web/delete_event_dialog.dart';
import 'package:flutter/material.dart';

import '../extension.dart';
import 'create_event_page.dart';

class DetailsPage extends StatelessWidget {
final CalendarEventData event;
final DateTime date;

const DetailsPage({
super.key,
required this.event,
required this.date,
});

const DetailsPage({super.key, required this.event});
@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -90,10 +97,8 @@ class DetailsPage extends StatelessWidget {
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
CalendarControllerProvider.of(context)
.controller
.remove(event);
onPressed: () async {
await _handleDeleteEvent(context);
Navigator.of(context).pop();
},
child: Text('Delete Event'),
Expand All @@ -111,7 +116,7 @@ class DetailsPage extends StatelessWidget {
),
);

if (result) {
if (result != null) {
Navigator.of(context).pop();
}
},
Expand All @@ -124,4 +129,33 @@ class DetailsPage extends StatelessWidget {
),
);
}

/// Handles the deletion of an event, showing a dialog for repeating events.
///
/// This method checks if the event is a repeating event. If it is, it shows
/// a dialog to the user to choose the deletion type (e.g., delete this
/// event, delete following events, delete all events).
/// If the event is not repeating, it defaults to deleting all occurrences
/// of the event.
Future<void> _handleDeleteEvent(BuildContext context) async {
DeleteEvent? result;
final isRepeatingEvent = event.recurrenceSettings != null &&
(event.recurrenceSettings?.frequency != RepeatFrequency.doNotRepeat);

if (isRepeatingEvent) {
result = await showDialog(
context: context,
builder: (_) => DeleteEventDialog(),
);
} else {
result = DeleteEvent.all;
}
if (result != null) {
CalendarControllerProvider.of(context).controller.deleteRecurrenceEvent(
date: date,
event: event,
deleteEventType: result,
);
}
}
}
63 changes: 63 additions & 0 deletions example/lib/pages/web/delete_event_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:calendar_view/calendar_view.dart';
import 'package:flutter/material.dart';

class DeleteEventDialog extends StatefulWidget {
@override
_RadioDialogState createState() => _RadioDialogState();
}

class _RadioDialogState extends State<DeleteEventDialog> {
DeleteEvent _selectedOption = DeleteEvent.current;

@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text('Delete recurring event '),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
RadioListTile<DeleteEvent>(
title: Text('This event'),
value: DeleteEvent.current,
groupValue: _selectedOption,
onChanged: (deleteType) {
if (deleteType != null) {
setState(() => _selectedOption = deleteType);
}
},
),
RadioListTile<DeleteEvent>(
title: Text('This and following events'),
value: DeleteEvent.following,
groupValue: _selectedOption,
onChanged: (deleteType) {
if (deleteType != null) {
setState(() => _selectedOption = deleteType);
}
},
),
RadioListTile<DeleteEvent>(
title: Text('All events'),
value: DeleteEvent.all,
groupValue: _selectedOption,
onChanged: (deleteType) {
if (deleteType != null) {
setState(() => _selectedOption = deleteType);
}
},
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.of(context).pop(_selectedOption),
child: Text('Done'),
),
],
);
}
}
Loading

0 comments on commit 790b419

Please sign in to comment.