CalendarWeekEvent.fromJson constructor
Factory constructor to create a CalendarWeekEvent from a JSON map. It handles parsing ISO date strings and hex color codes.
Implementation
factory CalendarWeekEvent.fromJson(Map<String, dynamic> json) {
final statusTextColorHex = json['statusTextColor'];
// The backend sometimes sends "0" to represent black.
final textColor = statusTextColorHex == '0'
? Colors.black
: parseColorHex(statusTextColorHex, Colors.white);
return CalendarWeekEvent(
id: json['id'],
// The API provides ISO strings, parse them as UTC
startDate: DateTime.parse(json['startDateIso'] + 'Z'),
endDate: DateTime.parse(json['endDateIso'] + 'Z'),
title: json['title'],
background: parseColorHex(json['statusColor'], Colors.blue),
iconUrl: json['iconUrl'],
textColor: textColor,
);
}