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

Change of time set event to 'all day' causes error #481

Closed SuperKrallan closed 3 months ago

SuperKrallan commented 1 year ago

Describe the bug When I create an event with a set time, like 12.00-13.00 in a specified day, and then open the event, setting the 'allday' to true, save it again I get "Device calendar plugin ran into an issue. Platform specific exception [500], with message :"The start date must be before the end date.", has been thrown." even though when I check the start and end date, this error statement is not true.

To Reproduce See above.

Expected behavior Edit: No error should be thrown. It should be saved as an all day event. If you later open the same all day event and remove the all day flag, then the time set from the beginning should be the shown.

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

Flutter doctor flutter doctor -v [✓] Flutter (Channel beta, 3.9.0-0.2.pre, on macOS 13.2.1 22D68 darwin-arm64, locale sv-SE) • Flutter version 3.9.0-0.2.pre on channel beta at /Library/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 0df8557c56 (3 veckor sedan), 2023-03-23 22:02:01 -0500 • Engine revision 1cc4b2d280 • Dart version 3.0.0 (build 3.0.0-290.3.beta) • DevTools version 2.22.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/Joakim/Library/Android/sdk • Platform android-33, build-tools 30.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E222b • CocoaPods version 1.12.0

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] Connected device (3 available) • EnSE (mobile) • XXXXXXXX-XXXXXXXXXXXXXX • ios • iOS 16.1.2 20B110 • macOS (desktop) • macos • darwin-arm64 • macOS 13.2.1 22D68 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 112.0.5615.49

[✓] Network resources • All expected network resources are available.

• No issues found!

Additional context Example code:

Event ev = Event(DM.defaultWriteCalendar?.id, title: 'Test', start: TZDateTime(DM.location, 2023, 4, 12, 12), end: TZDateTime(DM.location, 2023, 4, 12, 13) ); var createEventResult = await DM.deviceCalendarPlugin .createOrUpdateEvent(ev); ev.eventId = createEventResult!.data; if (createEventResult!.isSuccess) { print('Save successful'); } else { String errors = createEventResult.errors[0].errorMessage; for (int i = 1; i < createEventResult.errors.length; i++) { errors = '\n- ' + createEventResult.errors[i].errorMessage; } print('Errors: ' + errors); } await Future.delayed(Duration(seconds: 2)); ev.allDay = true; createEventResult = await DM.deviceCalendarPlugin .createOrUpdateEvent(ev); if (createEventResult!.isSuccess) { print('Save successful'); } else { String errors = createEventResult.errors[0].errorMessage; for (int i = 1; i < createEventResult.errors.length; i++) { errors = '\n- ' + createEventResult.errors[i].errorMessage; } print('Errors: ' + errors); }

SuperKrallan commented 1 year ago

Hmmm... Running the same code on Android emulator results in another error: 'Device calendar plugin ran into an issue. Platform specific exception [500], with message :"Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference", has been thrown.' I wonder if I am missing something here...

SuperKrallan commented 3 months ago

Now this works without me changing the code. Something done in the latest update? Closing the issue.