Skip to content

Commit

Permalink
feat: Fixes issue #378: ✨Added support for daily, weekly & yearly rec…
Browse files Browse the repository at this point in the history
…urrence event in month view
  • Loading branch information
shubham-jitiya-simform committed Nov 25, 2024
1 parent cc99a0e commit daf11ca
Show file tree
Hide file tree
Showing 13 changed files with 1,014 additions and 18 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
18 changes: 18 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,28 @@ 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)),
frequency: RepeatFrequency.daily,
recurrenceEndOn: RecurrenceEnd.after,
occurrences: 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,
recurrenceEndOn: RecurrenceEnd.after,
occurrences: 5,
),
title: "Wedding anniversary",
description: "Attend uncle's wedding anniversary.",
),
Expand Down
48 changes: 41 additions & 7 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/widgets/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({
required this.event,
required this.date,
super.key,
});

const DetailsPage({super.key, required this.event});
@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -83,17 +90,15 @@ class DetailsPage extends StatelessWidget {
SizedBox(
height: 10.0,
),
Text(event.description!),
Text(event.description!)
],
const SizedBox(height: 50),
Row(
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,
);
}
}
}
Loading

0 comments on commit daf11ca

Please sign in to comment.