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

Not working in the built and release mode #464

Closed ARAVINDKARATE closed 1 year ago

ARAVINDKARATE commented 1 year ago

I have integrated the device calendar plugin in my project and all the functions are working fine when I run the code but when I run it in release mode or make a built to release, these functionalities are not working

SuperKrallan commented 1 year ago

I am not having this problem. I think you need to be more specific what is not working for you in order to get better help.

zakton5 commented 1 year ago

Can confirm that adding events to a calendar does not work in release mode. I have used thoroughly tested this in debug mode and it works fine. In release mode, I am attempting to catch the error which fails the following is check. It is clearly a ResultError but somehow `ex is ResultError returns false. In summary, I have no way to figure out what the problem is.

try {
   await _calendarPlugin.createOrUpdateEvent(deviceEvent)
} catch (ex) {
  if (ex is ResultError) {
    print('result error');
  }
}
zakton5 commented 1 year ago

Apparently this library throws a List<ResultError> instead of a single ResultError. Here is my code:

final calendarsResult = await _calendarPlugin.retrieveCalendars();
if (!calendarsResult.isSuccess) {
  throw 'Failed to retrieve calendars';
} else if (calendarsResult.data == null || calendarsResult.data!.isEmpty) {
  throw 'Could not find any calendars';
}

calendarsResult.data!.forEach((calendar) {
  print('${calendar.id} ${calendar.name}, default: ${calendar.isDefault}, readOnly: ${calendar.isReadOnly}');
});

In debug mode it successfully retrieves all calendars and print the data correctly. In release mode, calendar.id, calendar.name, etc. are all null. So the core problem is that I don't actually have a calendarId to save events to because it is null.

thomassth commented 1 year ago

@ARAVINDKARATE @zakton5 Please provide more details, such as:

zakton5 commented 1 year ago

I found the section on the R8 proguard issue. I followed those steps and everything works well now.