buildCalendarUri static method

Uri buildCalendarUri(
  1. CalendarEvent? event
)

Builds a Google Calendar event URI.

This method constructs a URI to create a new event in Google Calendar. For more advanced or platform-agnostic calendar integration, consider using a dedicated package like add_2_calendar or platform channels.

event - The CalendarEvent object containing event details. Returns a Uri.https for Google Calendar. If event is null, an empty Uri is returned.

Implementation

static Uri buildCalendarUri(CalendarEvent? event) {
  if (event == null) return Uri();

  final Map<String, String?> queryParameters = {
    'action': 'TEMPLATE',
    'text': event.title,
    'dates':
        '${_formatDateTime(event.startDate)}/${_formatDateTime(event.endDate ?? event.startDate)}',
    if (event.description != null) 'details': event.description,
    if (event.location != null) 'location': event.location,
    if (event.allDay) 'sf': 'true', // Google Calendar specific for all day
  };

  return Uri.https(
    'calendar.google.com',
    '/calendar/render',
    queryParameters,
  );
}