toICalString method

String toICalString()

Implementation

String toICalString() {
  final buffer = StringBuffer();
  buffer.writeln('BEGIN:VTODO');
  buffer.writeln('UID:$uid');
  if (summary != null) {
    buffer.writeln('SUMMARY:$summary');
  }
  if (description != null) {
    buffer.writeln('DESCRIPTION:$description');
  }
  if (attachments != null && attachments!.isNotEmpty) {
    for (final attachment in attachments!) {
      buffer.writeln(attachment.toICalString());
    }
  }
  if (attendees != null && attendees!.isNotEmpty) {
    for (final attendee in attendees!) {
      buffer.writeln(attendee.toICalString());
    }
  }
  if (organizer != null) {
    buffer.writeln(organizer!.toICalString());
  }
  if (created != null) {
    buffer.writeln(
        'CREATED:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(created!.toUtc())}');
  }
  if (lastModified != null) {
    buffer.writeln(
        'LAST-MODIFIED:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(lastModified!.toUtc())}');
  }
  if (startDate != null) {
    buffer.writeln(
        'DTSTART:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(startDate!.toUtc())}');
  }
  if (dueDate != null) {
    buffer.writeln(
        'DUE:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(dueDate!.toUtc())}');
  }
  if (completedDate != null) {
    buffer.writeln(
        'COMPLETED:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(completedDate!.toUtc())}');
  }
  if (recurrenceRule != null) {
    buffer.writeln(recurrenceRule!.toICalString());
  }
  buffer.writeln('END:VTODO');
  return buffer.toString();
}