Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/screens/calendar/calendar_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,15 @@ class _CalendarScreenState extends State<CalendarScreen> {
_events[dateOnly] = [];
}

// For meetings, assume 1 hour duration
// Get duration from meeting data, default to 60 minutes
final durationMinutes = meeting['duration_minutes'] as int? ?? 60;
final endDateTime = meetingDate.add(Duration(minutes: durationMinutes));
Comment on lines +324 to +326
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Unsafe type cast may cause runtime exception.

The as int? cast on line 325 can throw a TypeError if the JSON deserializes the numeric value as num or double (e.g., 60.0 instead of 60). This is common with JSON parsing in Dart.

🛡️ Proposed fix using safe numeric conversion
         // Get duration from meeting data, default to 60 minutes
-        final durationMinutes = meeting['duration_minutes'] as int? ?? 60;
+        final durationMinutes = (meeting['duration_minutes'] as num?)?.toInt() ?? 60;
         final endDateTime = meetingDate.add(Duration(minutes: durationMinutes));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Get duration from meeting data, default to 60 minutes
final durationMinutes = meeting['duration_minutes'] as int? ?? 60;
final endDateTime = meetingDate.add(Duration(minutes: durationMinutes));
// Get duration from meeting data, default to 60 minutes
final durationMinutes = (meeting['duration_minutes'] as num?)?.toInt() ?? 60;
final endDateTime = meetingDate.add(Duration(minutes: durationMinutes));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/screens/calendar/calendar_screen.dart` around lines 324 - 326, The cast
on meeting['duration_minutes'] is unsafe and can crash if the JSON provides a
num/double; update the logic that computes durationMinutes (used to build
endDateTime) to accept num/double or int safely: read the raw value from meeting
(e.g., durationRaw), check for null, then if it's a num convert to int via
toInt(), if it's already an int use it, otherwise fall back to 60; then use that
safe int for endDateTime calculation (referencing durationMinutes,
meeting['duration_minutes'], meetingDate, and endDateTime).

_events[dateOnly]!.add(CalendarEvent(
title: meeting['title'] ?? 'Untitled Meeting',
startTime:
TimeOfDay(hour: meetingDate.hour, minute: meetingDate.minute),
endTime:
TimeOfDay(hour: meetingDate.hour + 1, minute: meetingDate.minute),
TimeOfDay(hour: endDateTime.hour, minute: endDateTime.minute),
Comment on lines +326 to +332
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Edge case: Meetings spanning midnight will display confusing times.

When a meeting crosses midnight (e.g., starts at 23:00 with 120-minute duration), endDateTime will be on the next day, but TimeOfDay only captures hour and minute without date context. The event card would show "11:00 PM - 1:00 AM" yet only appear on the first day's calendar. Consider whether this edge case warrants handling or documentation.

💡 Optional: Add a comment documenting the limitation or clamp the end time
         // Get duration from meeting data, default to 60 minutes
-        final durationMinutes = meeting['duration_minutes'] as int? ?? 60;
+        final durationMinutes = (meeting['duration_minutes'] as num?)?.toInt() ?? 60;
         final endDateTime = meetingDate.add(Duration(minutes: durationMinutes));
+        
+        // Note: If meeting spans midnight, endTime will show next day's time
+        // but event only appears on start date. Consider clamping to 23:59 if needed.
         _events[dateOnly]!.add(CalendarEvent(
           title: meeting['title'] ?? 'Untitled Meeting',
           startTime:
               TimeOfDay(hour: meetingDate.hour, minute: meetingDate.minute),
           endTime:
               TimeOfDay(hour: endDateTime.hour, minute: endDateTime.minute),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/screens/calendar/calendar_screen.dart` around lines 326 - 332, The
current logic builds a single CalendarEvent using TimeOfDay from meetingDate and
endDateTime which loses date context so meetings spanning midnight (meetingDate
+ durationMinutes) only show on the start day; update the population logic in
the block that uses meetingDate, endDateTime, TimeOfDay and _events[dateOnly] to
detect if endDateTime.day != meetingDate.day and in that case split the meeting
into two CalendarEvent entries (one from start time to 23:59 on the start date
and a second from 00:00 to the actual end time on the next date) and insert each
into the proper _events map keys, or alternatively add a clear comment near
CalendarEvent creation documenting this limitation if you prefer not to split
events.

type: EventType.meeting,
id: meeting['id'],
));
Expand Down