Skip to content

Commit

Permalink
🐛 Fixes issue #290.
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthBaraiya committed Sep 13, 2024
1 parent 76c5430 commit 75e6d09
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 128 deletions.
101 changes: 59 additions & 42 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,60 +39,77 @@ List<CalendarEventData> _events = [
date: _now,
title: "Project meeting",
description: "Today is project meeting.",
startTime: DateTime(_now.year, _now.month, _now.day, 18, 30),
endTime: DateTime(_now.year, _now.month, _now.day, 22),
startTime: DateTime(_now.year, _now.month, _now.day, 6),
endTime: DateTime(_now.year, _now.month, _now.day, 7),
),
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),
title: "Wedding anniversary",
description: "Attend uncle's wedding anniversary.",
date: _now,
title: "Project meeting",
description: "Today is project meeting.",
startTime: DateTime(_now.year, _now.month, _now.day, 7),
endTime: DateTime(_now.year, _now.month, _now.day, 7, 45),
),
CalendarEventData(
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 14),
endTime: DateTime(_now.year, _now.month, _now.day, 17),
startTime: DateTime(_now.year, _now.month, _now.day, 7),
endTime: DateTime(_now.year, _now.month, _now.day, 15),
title: "Football Tournament",
description: "Go to football tournament.",
),
CalendarEventData(
date: _now.add(Duration(days: 3)),
startTime: DateTime(_now.add(Duration(days: 3)).year,
_now.add(Duration(days: 3)).month, _now.add(Duration(days: 3)).day, 10),
endTime: DateTime(_now.add(Duration(days: 3)).year,
_now.add(Duration(days: 3)).month, _now.add(Duration(days: 3)).day, 14),
title: "Sprint Meeting.",
description: "Last day of project submission for last year.",
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 7, 45),
endTime: DateTime(_now.year, _now.month, _now.day, 8, 30),
title: "This is football",
description: "Go to football tournament.",
),
CalendarEventData(
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 7, 45),
endTime: DateTime(_now.year, _now.month, _now.day, 8, 30),
title: "Wedding anniversary 2",
description: "Attend 2nd uncle's wedding anniversary.",
),
CalendarEventData(
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 8, 30),
endTime: DateTime(_now.year, _now.month, _now.day, 9, 15),
title: "Wedding anniversary",
description: "Attend uncle's wedding anniversary.",
),
CalendarEventData(
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 8, 30),
endTime: DateTime(_now.year, _now.month, _now.day, 9, 15),
title: "Wedding anniversary 3rd",
description: "Attend Another uncle's wedding anniversary.",
),
CalendarEventData(
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 9, 15),
endTime: DateTime(_now.year, _now.month, _now.day, 10),
title: "Wedding anniversary",
description: "Attend uncle's wedding anniversary.",
),
CalendarEventData(
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 12, 15),
endTime: DateTime(_now.year, _now.month, _now.day, 13),
title: "Wedding anniversary",
description: "Attend uncle's wedding anniversary.",
),
CalendarEventData(
date: _now.subtract(Duration(days: 2)),
startTime: DateTime(
_now.subtract(Duration(days: 2)).year,
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
14),
endTime: DateTime(
_now.subtract(Duration(days: 2)).year,
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
16),
title: "Team Meeting",
description: "Team Meeting",
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 13),
endTime: DateTime(_now.year, _now.month, _now.day, 14),
title: "Wedding anniversary",
description: "Attend uncle's wedding anniversary.",
),
CalendarEventData(
date: _now.subtract(Duration(days: 2)),
startTime: DateTime(
_now.subtract(Duration(days: 2)).year,
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
10),
endTime: DateTime(
_now.subtract(Duration(days: 2)).year,
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
12),
title: "Chemistry Viva",
description: "Today is Joe's birthday.",
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 13),
endTime: DateTime(_now.year, _now.month, _now.day, 14),
title: "Wedding anniversary 4",
description: "Attend uncle's uncle's wedding anniversary.",
),
];
2 changes: 1 addition & 1 deletion example/lib/widgets/day_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DayViewWidget extends StatelessWidget {
width: width,
startDuration: Duration(hours: 8),
showHalfHours: true,
heightPerMinute: 3,
heightPerMinute: 1,
timeLineBuilder: _timeLineBuilder,
hourIndicatorSettings: HourIndicatorSettings(
color: Theme.of(context).dividerColor,
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
intl:
flutter_colorpicker: ^0.6.0
flutter_colorpicker: ^1.1.0
calendar_view:
path: ../

Expand Down
20 changes: 19 additions & 1 deletion lib/src/calendar_event_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CalendarEventData<T extends Object?> {

/// Defines the start time of the event.
/// [endTime] and [startTime] will defines time on same day.
/// This is required when you are using [CalendarEventData] for [DayView]
/// This is required when you are using [CalendarEventData] for [DayView] or [WeekView]
final DateTime? startTime;

/// Defines the end time of the event.
Expand Down Expand Up @@ -81,6 +81,24 @@ class CalendarEventData<T extends Object?> {
(startTime!.isDayStart && endTime!.isDayStart));
}

Duration get duration {
if (isFullDayEvent) return Duration(days: 1);

final now = DateTime.now();

final end = now.copyFromMinutes(endTime!.getTotalMinutes);
final start = now.copyFromMinutes(startTime!.getTotalMinutes);

if (end.isDayStart) {
final difference =
end.add(Duration(days: 1) - Duration(seconds: 1)).difference(start);

return difference + Duration(seconds: 1);
} else {
return end.difference(start);
}
}

/// Returns a boolean that defines whether current event is occurring on
/// [currentDate] or not.
///
Expand Down
9 changes: 6 additions & 3 deletions lib/src/event_arrangers/merge_event_arranger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {

//Checking if startTime and endTime are correct
for (final event in events) {
if (event.startTime == null || event.endTime == null) {
debugLog('startTime or endTime is null for ${event.title}');
continue;
}

// Checks if an event has valid start and end time.
if (event.startTime == null ||
event.endTime == null ||
event.endTime!.getTotalMinutes <= event.startTime!.getTotalMinutes) {
if (event.endTime!.getTotalMinutes <= event.startTime!.getTotalMinutes) {
if (!(event.endTime!.getTotalMinutes == 0 &&
event.startTime!.getTotalMinutes > 0)) {
assert(() {
Expand Down
Loading

0 comments on commit 75e6d09

Please sign in to comment.