show static method

Future show(
  1. BuildContext context, {
  2. String? calendarId,
  3. String? eventId,
  4. String? title,
  5. String? description,
  6. int? startDate,
  7. int? endDate,
  8. bool? allDay,
})

Implementation

static Future<dynamic> show(BuildContext context,
    {String? calendarId,
    String? eventId,
    String? title,
    String? description,
    int? startDate,
    int? endDate,
    bool? allDay}) async {
  if (EditCalendarEventPage.currentTimeZone == null) {
    tz.initializeTimeZones();
    currentTimeZone= await FlutterTimezone.getLocalTimezone();
  }
  List<Calendar> calendars = (await DeviceCalendarPlugin().retrieveCalendars())
      .data?.toList() ?? [];
  Event? event;
  if (eventId != null) {
    if (calendarId != null) {
      event = (await DeviceCalendarPlugin().retrieveEvents(
          calendarId, RetrieveEventsParams(eventIds: [eventId]))).data?.firstOrNull;
    }
    if (event == null) {
      for (final cal in calendars) {
        final events = await DeviceCalendarPlugin().retrieveEvents(
            cal.id, RetrieveEventsParams(eventIds: [eventId]));
        final evnt = events.data?.firstOrNull;
        if (evnt != null) {
          event = evnt;
          break;
        }
      }
    }
  }
  calendars = calendars.where((element) => element.isReadOnly == false)
          .toList();

  Calendar? calendar;

  if (calendarId != null) {
    calendar =
        calendars.firstWhereOrNull((element) => element.id == calendarId);
  }
  if (calendar == null && event?.calendarId != null) {
    calendar = calendars
        .firstWhereOrNull((element) => element.id == event?.calendarId);
  }
  calendar ??= calendars.firstWhereOrNull((element) =>
      !(element.isReadOnly ?? true) && (element.isDefault ?? false));
  calendar ??=
      calendars.firstWhereOrNull((element) => !(element.isReadOnly ?? true));
  if (!context.mounted) {
    return;
  }
  final page = EditCalendarEventPage(
    event: event,
    calendar: calendar,
    title: title,
    description: description,
    startDate: startDate,
    endDate: endDate,
    allDay: allDay,
  );
  if (MacosTheme.maybeOf(context) != null) {
    return MultiPlatformDialog.show(
        context, page,
        barrierDismissible: true, maxWidth: 500, maxHeight: 548);
  } else {
    return Navigator.push(
      context,
      MaterialPageRoute(
          builder: (context) => page),
    );
  }
}