toICalString method
Implementation
String toICalString() {
final buffer = StringBuffer();
buffer.writeln(_foldLine('BEGIN:VEVENT'));
if (startDate != null) {
if (startDate!.isAfter(DateTime(2022, 10, 09)) &&
startDate!.isBefore(DateTime(2022, 10, 11))) {
print('startDate: $startDate');
print('endDate: $endDate');
print('timeZone: $timeZone');
}
if (timeZone != null) {
if (timeZone!.tzId == 'DATE') {
buffer.writeln(_foldLine(
'DTSTART;VALUE=DATE:${DateFormat('yyyyMMdd').format(startDate!)}'));
if (endDate != null) {
buffer.writeln(_foldLine(
'DTEND;VALUE=DATE:${DateFormat('yyyyMMdd').format(endDate!)}'));
}
} else {
buffer.writeln(_foldLine(
'DTSTART;TZID=${timeZone!.tzId}:${DateFormat('yyyyMMdd\'T\'HHmmss').format(startDate!)}'));
if (endDate != null) {
buffer.writeln(_foldLine(
'DTEND;TZID=${timeZone!.tzId}:${DateFormat('yyyyMMdd\'T\'HHmmss').format(endDate!)}'));
}
}
} else {
buffer.writeln(_foldLine(
'DTSTART:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(startDate!)}'));
if (endDate != null) {
buffer.writeln(_foldLine(
'DTEND:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(endDate!)}'));
}
}
}
if (recurrenceRule != null) {
buffer.writeln(_foldLine(recurrenceRule!.toICalString()));
}
if (xDates != null) {
for (final xDate in xDates!) {
buffer.writeln(_foldLine(xDate.toICalString()));
}
}
if (stamp != null) {
buffer.writeln(_foldLine(
'DTSTAMP:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(stamp!.toUtc())}'));
}
if (organizer != null) {
buffer.writeln(_foldLine(organizer!.toICalString()));
}
buffer.writeln(_foldLine('UID:$uid'));
if (attendees != null && attendees!.isNotEmpty) {
for (final attendee in attendees!) {
buffer.writeln(_foldLine(attendee.toICalString()));
}
}
if (customProperties != null &&
customProperties!.isNotEmpty &&
customProperties!.containsKey('X-GOOGLE-CONFERENCE')) {
for (final key in customProperties!.keys) {
if (!key.contains('X-LIC')) {
buffer.writeln(_foldLine('$key:${customProperties![key]}'));
}
}
}
if (eventClass != null) {
buffer.writeln(_foldLine('CLASS:$eventClass'));
}
if (recurrenceId != null) {
buffer.writeln(_foldLine('RECURRENCE-ID;$recurrenceId'));
}
if (created != null) {
buffer.writeln(_foldLine(
'CREATED:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(created!.toUtc())}'));
}
if (description != null) {
buffer.writeln(_foldLine('DESCRIPTION:$description'));
}
if (lastModified != null) {
buffer.writeln(_foldLine(
'LAST-MODIFIED:${DateFormat('yyyyMMdd\'T\'HHmmss\'Z\'').format(lastModified!.toUtc())}'));
}
if (location != null) {
buffer.writeln(_foldLine(location!.toICalString()));
}
if (sequence != null) {
buffer.writeln(_foldLine('SEQUENCE:$sequence'));
}
if (status != null) {
buffer.writeln(_foldLine(status!.toICalString()));
}
if (summary != null) {
buffer.writeln(_foldLine('SUMMARY:$summary'));
}
if (transparency != null) {
buffer.writeln(_foldLine('TRANSP:$transparency'));
}
if (attachments != null && attachments!.isNotEmpty) {
for (final attachment in attachments!) {
buffer.writeln(_foldLine(attachment.toICalString()));
}
}
if (customProperties != null &&
customProperties!.isNotEmpty &&
!customProperties!.containsKey('X-GOOGLE-CONFERENCE')) {
for (final key in customProperties!.keys) {
if (!key.contains('X-LIC')) {
buffer.writeln(_foldLine('$key:${customProperties![key]}'));
}
}
}
if (customProperties != null && customProperties!.isNotEmpty) {
for (final key in customProperties!.keys) {
if (key.contains('X-LIC')) {
buffer.writeln(_foldLine('$key:${customProperties![key]}'));
}
}
}
if (attachFiles != null && attachFiles!.isNotEmpty) {
for (final attachFile in attachFiles!) {
buffer.writeln(_foldLine(attachFile.toICalString()));
}
}
buffer.writeln(_foldLine('END:VEVENT'));
return buffer.toString();
}