@@ -32,11 +32,13 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
3232 required double width,
3333 required double heightPerMinute,
3434 required int startHour,
35+ required DateTime calendarViewDate,
3536 }) {
3637 // TODO: Right now all the events that are passed in this function must be
3738 // sorted in ascending order of the start time.
3839 //
3940 final arrangedEvents = < OrganizedCalendarEventData <T >> [];
41+ final startHourInMinutes = startHour * 60 ;
4042
4143 //Checking if startTime and endTime are correct
4244 for (final event in events) {
@@ -46,7 +48,8 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
4648 }
4749
4850 // Checks if an event has valid start and end time.
49- if (event.endTime! .getTotalMinutes <= event.startTime! .getTotalMinutes) {
51+ if (event.endDate.millisecondsSinceEpoch <
52+ event.date.millisecondsSinceEpoch) {
5053 if (! (event.endTime! .getTotalMinutes == 0 &&
5154 event.startTime! .getTotalMinutes > 0 )) {
5255 assert (() {
@@ -67,13 +70,51 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
6770 final startTime = event.startTime! ;
6871 final endTime = event.endTime! ;
6972
70- // startTime.getTotalMinutes returns the number of minutes from 00h00 to the beginning of the event
71- // But the first hour to be displayed (startHour) could be 06h00, so we have to substract
72- // The number of minutes from 00h00 to startHour which is equal to startHour * 60
73- final eventStart = startTime.getTotalMinutes - (startHour * 60 );
74- final eventEnd = endTime.getTotalMinutes - (startHour * 60 ) == 0
75- ? Constants .minutesADay - (startHour * 60 )
76- : endTime.getTotalMinutes - (startHour * 60 );
73+ int eventStart;
74+ int eventEnd;
75+
76+ if (event.isRangingEvent) {
77+ // Handle multi-day events differently based on which day is currently being viewed
78+ final isStartDate =
79+ calendarViewDate.isAtSameMomentAs (event.date.withoutTime);
80+ final isEndDate =
81+ calendarViewDate.isAtSameMomentAs (event.endDate.withoutTime);
82+
83+ if (isStartDate && isEndDate) {
84+ // Single day event with start and end time
85+ eventStart = startTime.getTotalMinutes - (startHourInMinutes);
86+ eventEnd = endTime.getTotalMinutes - (startHourInMinutes) <= 0
87+ ? Constants .minutesADay - (startHourInMinutes)
88+ : endTime.getTotalMinutes - (startHourInMinutes);
89+ } else if (isStartDate) {
90+ // First day - show from start time to end of day
91+ eventStart = startTime.getTotalMinutes - (startHourInMinutes);
92+ eventEnd = Constants .minutesADay;
93+ } else if (isEndDate) {
94+ // Last day - show from start of day to end time
95+ eventStart = 0 ;
96+ eventEnd = endTime.getTotalMinutes - (startHourInMinutes) <= 0
97+ ? Constants .minutesADay - (startHourInMinutes)
98+ : endTime.getTotalMinutes - (startHourInMinutes);
99+ } else {
100+ // Middle days - show full day
101+ eventStart = 0 ;
102+ eventEnd = Constants .minutesADay;
103+ }
104+ } else {
105+ // Single day event - use normal start/end times
106+ eventStart = startTime.getTotalMinutes - (startHourInMinutes);
107+ eventEnd = endTime.getTotalMinutes - (startHourInMinutes) <= 0
108+ ? Constants .minutesADay - (startHourInMinutes)
109+ : endTime.getTotalMinutes - (startHourInMinutes);
110+ }
111+
112+ // Ensure values are within valid range
113+ eventStart = math.max (0 , eventStart);
114+ eventEnd = math.min (
115+ Constants .minutesADay - (startHourInMinutes),
116+ eventEnd,
117+ );
77118
78119 final arrangeEventLen = arrangedEvents.length;
79120
@@ -97,8 +138,13 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
97138
98139 if (eventIndex == - 1 ) {
99140 final top = eventStart * heightPerMinute;
100- final bottom = eventEnd * heightPerMinute == height
101- ? 0.0
141+
142+ // Calculate visibleMinutes (the total minutes displayed in the view)
143+ final visibleMinutes = Constants .minutesADay - (startHourInMinutes);
144+
145+ // Check if event ends at or beyond the visible area
146+ final bottom = eventEnd >= visibleMinutes
147+ ? 0.0 // Event extends to bottom of view
102148 : height - eventEnd * heightPerMinute;
103149
104150 final newEvent = OrganizedCalendarEventData <T >(
@@ -109,6 +155,7 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
109155 startDuration: startTime.copyFromMinutes (eventStart),
110156 endDuration: endTime.copyFromMinutes (eventEnd),
111157 events: [event],
158+ calendarViewDate: calendarViewDate,
112159 );
113160
114161 arrangedEvents.add (newEvent);
@@ -126,8 +173,13 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
126173 final endDuration = math.max (eventEnd, arrangedEventEnd);
127174
128175 final top = startDuration * heightPerMinute;
129- final bottom = endDuration * heightPerMinute == height
130- ? 0.0
176+
177+ // Calculate visibleMinutes (the total minutes displayed in the view)
178+ final visibleMinutes = Constants .minutesADay - (startHourInMinutes);
179+
180+ // Check if event ends at or beyond the visible area
181+ final bottom = endDuration >= visibleMinutes
182+ ? 0.0 // Event extends to bottom of view
131183 : height - endDuration * heightPerMinute;
132184
133185 final newEvent = OrganizedCalendarEventData <T >(
@@ -140,6 +192,7 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
140192 endDuration:
141193 arrangedEventData.endDuration.copyFromMinutes (endDuration),
142194 events: arrangedEventData.events..add (event),
195+ calendarViewDate: calendarViewDate,
143196 );
144197
145198 arrangedEvents[eventIndex] = newEvent;
0 commit comments