Skip to content

Commit

Permalink
✨ Adds new method updateEvent to update the existing event in the cal…
Browse files Browse the repository at this point in the history
…endar view.

- Fixes issue #125
  • Loading branch information
PRBaraiya committed Nov 23, 2023
1 parent 672b2cf commit f6d8bfe
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 99 deletions.
48 changes: 45 additions & 3 deletions lib/src/calendar_event_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CalendarEventData<T extends Object?> {
final String title;

/// Description of the event.
final String description;
final String? description;

/// Defines color of event.
/// This color will be used in default widgets provided by plugin.
Expand All @@ -43,10 +43,14 @@ class CalendarEventData<T extends Object?> {
/// Define style of description.
final TextStyle? descriptionStyle;

/// Stores all the events on [date]
/// Stores all the events on [date].
///
/// If [startTime] and [endTime] both are 0 or either of them is null, then
/// event will be considered a full day event.
///
const CalendarEventData({
required this.title,
this.description = "",
this.description,
this.event,
this.color = Colors.blue,
this.startTime,
Expand All @@ -59,6 +63,18 @@ class CalendarEventData<T extends Object?> {

DateTime get endDate => _endDate ?? date;

bool get isRangingEvent {
final diff = endDate.withoutTime.difference(date.withoutTime).inDays;

return diff > 0 && !isFullDayEvent;
}

bool get isFullDayEvent {
return (startTime == null ||
endTime == null ||
(startTime!.isDayStart && endTime!.isDayStart));
}

Map<String, dynamic> toJson() => {
"date": date,
"startTime": startTime,
Expand All @@ -69,6 +85,32 @@ class CalendarEventData<T extends Object?> {
"endDate": endDate,
};

CalendarEventData<T> copyWith({
String? title,
String? description,
T? event,
Color? color,
DateTime? startTime,
DateTime? endTime,
TextStyle? titleStyle,
TextStyle? descriptionStyle,
DateTime? endDate,
DateTime? date,
}) {
return CalendarEventData(
title: title ?? this.title,
date: date ?? this.date,
startTime: startTime ?? this.startTime,
endTime: endTime ?? this.endTime,
color: color ?? this.color,
description: description ?? this.description,
descriptionStyle: descriptionStyle ?? this.descriptionStyle,
endDate: endDate ?? this.endDate,
event: event ?? this.event,
titleStyle: titleStyle ?? this.titleStyle,
);
}

@override
String toString() => toJson().toString();

Expand Down
8 changes: 4 additions & 4 deletions lib/src/components/day_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RoundedEventTile extends StatelessWidget {
final String title;

/// Description of the tile.
final String description;
final String? description;

/// Background color of tile.
/// Default color is [Colors.blue]
Expand Down Expand Up @@ -49,7 +49,7 @@ class RoundedEventTile extends StatelessWidget {
required this.title,
this.padding = EdgeInsets.zero,
this.margin = EdgeInsets.zero,
this.description = "",
this.description,
this.borderRadius = BorderRadius.zero,
this.totalEvents = 1,
this.backgroundColor = Colors.blue,
Expand Down Expand Up @@ -83,12 +83,12 @@ class RoundedEventTile extends StatelessWidget {
overflow: TextOverflow.fade,
),
),
if (description.isNotEmpty)
if (description?.isNotEmpty ?? false)
Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: 15.0),
child: Text(
description,
description!,
style: descriptionStyle ??
TextStyle(
fontSize: 17,
Expand Down
Loading

0 comments on commit f6d8bfe

Please sign in to comment.