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

Resaving an allDay event causes error #482

Closed SuperKrallan closed 3 months ago

SuperKrallan commented 1 year ago

Describe the bug After creating an all day event you cannot save it again.

To Reproduce The following code which just creates an event, and then saves is again works fine:

Event ev = Event(DM.defaultWriteCalendar?.id, title: 'Test', start: TZDateTime(DM.location, 2023, 4, 13, 12), end: TZDateTime(DM.location, 2023, 4, 13, 13), allDay: false ); 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)); 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); }

...but just changing the 'allDay: false' in the code to 'allDay: true' results in the error

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.

So trying to save a previously saved all day event does not work.

Expected behavior That the event will be saved without error.

Screenshots Optional, add screenshots if it helps explain your problem.

Device(s) tested Device: iPhone 13 mini OS: iOS 16.1.2 Plugin version 4.3.1

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

✓] 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 Most likely related to the issue

SuperKrallan commented 1 year ago

Proposal: In the file _devicecalendar.dart, in the method Future<Result?> createOrUpdateEvent(Event? event) , add Platform.isAndroid as a condition to the line if (event.allDay == true) { so it instead reads if (event.allDay == true && Platform.isAndroid) {, because it seems this check is not necessary for iOS.

SuperKrallan commented 3 months ago

Been a while since I worked on my calendar project, and I can no longer reproduce this issue even though I have not changed the part of the code that is involved in this matter. Perhaps something fixed with the 4.3.2 update? Anyway, closing this issue.