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
267 stars 267 forks source link

Recurrent event has error on samsung/huawei #447

Open cga2351 opened 1 year ago

cga2351 commented 1 year ago

Describe the bug can't create forever recurrent event on samsung s10, also failed on huawei mate30.

To Reproduce on samsung s10, I add a recurrent event, with following Event param:

    var calendarEvent = Event(
      "calendarId",
      reminders: [Reminder(minutes: 0)],
      title: "title",
      description: "description",
      start: startTime,
      end: endTime,
      recurrenceRule: RecurrenceRule(
        RecurrenceFrequency.Daily,
        interval: 1,
      ),
    );

but, it only create serveral events, not forever.

Expected behavior create forever recurrent event.

Device(s) tested This can be very important as not all device vendors do calendar in the same way.

Flutter doctor Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.3.3, on Microsoft Windows [版本 10.0.19044.2006], locale zh-CN) [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.0) [√] Android Studio (version 2021.1) [√] Android Studio (version 4.1) [√] IntelliJ IDEA Community Edition (version 2021.1) [√] Connected device (4 available) [√] HTTP Host Availability

Additional context I checked the plugins source code, maybe the following function caused it?

private fun buildEventContentValues(event: Event, calendarId: String): ContentValues {
        val values = ContentValues()
        val duration: String? = null
        values.put(Events.ALL_DAY, event.eventAllDay)
        values.put(Events.DTSTART, event.eventStartDate!!)
        values.put(Events.EVENT_TIMEZONE, getTimeZone(event.eventStartTimeZone).id)
        values.put(Events.DTEND, event.eventEndDate!!)
        values.put(Events.EVENT_END_TIMEZONE, getTimeZone(event.eventEndTimeZone).id)
        values.put(Events.TITLE, event.eventTitle)
        values.put(Events.DESCRIPTION, event.eventDescription)
        values.put(Events.EVENT_LOCATION, event.eventLocation)
        values.put(Events.CUSTOM_APP_URI, event.eventURL)
        values.put(Events.CALENDAR_ID, calendarId)
        values.put(Events.DURATION, duration)
        values.put(Events.AVAILABILITY, getAvailability(event.availability))

        if (event.recurrenceRule != null) {
            val recurrenceRuleParams = buildRecurrenceRuleParams(event.recurrenceRule!!)
            values.put(Events.RRULE, recurrenceRuleParams)
        }
        return values
    }

because I found the description on android doc of android CalendarContract.Events:

Insert

When inserting a new event the following fields must be included:

as above source code, the plugin only set DTEND, and set DURATION null.

and I also test android api, and set ContentValue that 1.no Events.DTEND 2.Events.DURATION = "PT1H" and it can create recurrent event succesfully.

cga2351 commented 1 year ago

I noticed that above code is the master branch, the develop branch has already add the event.DURATION param according to the endDate.

I cloned the develop branch code and added to my flutter project to test, it create forever recurrent event successfully, But, it seems like the pub.dev release is not released with the newest code? can you release newest version to the pub.dev? thanks.