createEvent static method

VCalendar createEvent({
  1. required DateTime start,
  2. String? organizerEmail,
  3. OrganizerProperty? organizer,
  4. List<String>? attendeeEmails,
  5. List<AttendeeProperty>? attendees,
  6. bool? rsvp,
  7. DateTime? end,
  8. IsoDuration? duration,
  9. String? location,
  10. Uri? url,
  11. String? summary,
  12. String? description,
  13. String productId = 'enough_icalendar',
  14. String? calendarScale,
  15. String? timezoneId,
  16. DateTime? timeStamp,
  17. String? uid,
  18. bool? isAllDayEvent,
  19. Method method = Method.request,
})

Creates an event from the specified organizer resp. organizerEmail on the given start datetime and either the end or duration.

Any other settings are optional.

Implementation

static VCalendar createEvent({
  required DateTime start,
  String? organizerEmail,
  OrganizerProperty? organizer,
  List<String>? attendeeEmails,
  List<AttendeeProperty>? attendees,
  bool? rsvp,
  DateTime? end,
  IsoDuration? duration,
  String? location,
  Uri? url,
  String? summary,
  String? description,
  String productId = 'enough_icalendar',
  String? calendarScale,
  String? timezoneId,
  DateTime? timeStamp,
  String? uid,
  bool? isAllDayEvent,
  Method method = Method.request,
}) {
  assert(organizer != null || organizerEmail != null,
      'Either organizer or organizerEmail needs to be specified.');
  assert(end != null || duration != null,
      'Either end or duration must be specified.');
  final calendar = VCalendar()
    ..calendarScale = calendarScale
    ..productId = productId
    ..version = '2.0'
    ..timezoneId = timezoneId
    ..method = method;
  final event = VEvent(parent: calendar);
  calendar.children.add(event);
  organizer ??= OrganizerProperty.create(email: organizerEmail);
  event
    ..timeStamp = timeStamp ?? DateTime.now()
    ..uid = uid ?? createUid(organizerUri: organizer!.uri)
    ..start = start
    ..end = end
    ..duration = duration
    ..organizer = organizer
    ..summary = summary
    ..description = description
    ..location = location
    ..url = url
    ..isAllDayEvent = isAllDayEvent;
  if (attendees != null) {
    event.attendees = attendees;
  } else if (attendeeEmails != null) {
    event.attendees = attendeeEmails
        .map((email) =>
            AttendeeProperty.create(attendeeEmail: email, rsvp: rsvp)!)
        .toList();
  }
  return calendar;
}