parse static method
Implementation
static VTodo parse(String vtodoString) {
final lines = vtodoString.split('\n');
String? uid;
DateTime? dtstamp;
DateTime? due;
String? summary;
String? description;
TODOStatus? status;
String? priority;
RecurrenceRule? rrule;
List<DateTime>? exDates;
List<Attendee>? attendees;
MailTo? organizer;
String? contact;
for (var line in lines) {
final parts = line.split(':');
if (parts.length < 2) continue;
final key = parts[0];
final value = parts.getRange(1, parts.length).join(':');
switch (key) {
case 'UID':
uid = value;
break;
case 'DTSTAMP':
dtstamp = DateTime.parse(value.replaceAll('Z', ''));
break;
case 'DUE':
due = DateTime.parse(value.replaceAll('Z', ''));
break;
case 'SUMMARY':
summary = value;
break;
case 'DESCRIPTION':
description = value;
break;
case 'STATUS':
status = TODOStatus.values.firstWhere((e)=> Heplers.camelToSnake(e.name).toUpperCase() == value) ;
break;
case 'PRIORITY':
priority = value;
break;
case 'RRULE':
rrule = RecurrenceRule.parse(value);
break;
case 'EXDATE':
exDates ??= [];
exDates.add(DateTime.parse(value.replaceAll('Z', '')));
break;
case 'ATTENDEE':
attendees ??= [];
attendees.add(Attendee.parse(value));
break;
case 'ORGANIZER':
organizer = MailTo(value);
break;
case 'CONTACT':
contact = value;
break;
}
}
return VTodo(
uid: uid ?? '',
dtstamp: dtstamp ?? DateTime.now(),
summary: summary ?? '',
due: due ?? DateTime.now().add(const Duration(hours: 1)),
description: description,
status: status,
priority: priority,
rrule: rrule,
exDates: exDates,
attendees: attendees,
organizer: organizer,
contact: contact,
);
}