builttoroam / device_calendar

A cross platform plugin for modifying calendars on the user's device
https://pub.dev/packages/device_calendar
BSD 3-Clause "New" or "Revised" License
260 stars 263 forks source link

AllDay events are not displayed in the calendar #426

Closed yarmel closed 2 years ago

yarmel commented 2 years ago

Could you please provide a short example of how to set the AllDay event? I can't understand how to set it. With or without end date. Tried different ways bo with no luck.

My example

static Future<String?> update(Map eventData) async {
    DateTime date = eventData['startAt'];
    int timeline = int.parse(eventData['timeline']);
    bool allDay = date.hour == 0;

    Console.d('Date: $date'); // Date: 2022-05-22 00:00:00.000
    Console.d('Is all Day: $allDay'); // Is all Day: true
    Console.d('Timeline: $timeline'); // Timeline: 25 minutes

    dc.Event dcEvent = dc.Event(
      eventData['cid'],
      eventId: eventData['eid'],
      title: eventData['title'],
      description: eventData['notes'],
      allDay: allDay,
      start: TZDateTime.from(date, local),
      end: allDay ? null : TZDateTime.from(date.add(Duration(minutes: timeline)), local),
    );

    try {
      dc.Result<String>? result = await plugin.createOrUpdateEvent(dcEvent);
      if (result != null && result.data!.isNotEmpty) {
        if (debug) Console.i('Calendar', 'event ID: ${result.data} added');
        return result.data;
      } else {
        return null;
      }
    } catch (e) {
      if (debug) Console.e('Calendar', 'error on check calendar permissions. $e');
      return null;
    }
  }

Also, there is no information and docs on how to set recurrenceRule on events. Nice and helpful plugin but would be great to add short examples for different recurrent events.

Thank you.