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

Creating duplicate calendars #492

Open milindgoel15 opened 11 months ago

milindgoel15 commented 11 months ago

Not sure its a bug or expected behavior or something can be improved.

Describe the bug So when we create a new calendar to add some event for first time, the calendar is successfully created. But when we add a second event to calendar, it creates another calendar with different id under the same name (see screenshot below). And when user deletes the event from the calendar app itself, it wont delete the calendar result which was created using createCalendar() making so too many redundant instances in the end never to be used again.

To Reproduce Steps to reproduce the behavior:

  1. Use the code provided or create a button that initiates a calendar and adds the event to calendar.
  2. Run it more than 1 times
  3. Open calendar app and you will see duplicate event names with different ids which cant be deleted by user.

Expected behavior When calendar was created for the first as a local account, the plugin checks if the local account already exists. If it does, it checks if the event is already created. If it that exists, it uses its data to create events.

Actual behavior No method of checking if the calendar event exists. Making the app create duplicate results with different id's each time.

Screenshots duplicate ids

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.10.5, on Microsoft Windows [Version 10.0.22621.1992], locale en-IN)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Android Studio (version 2022.2)
[✓] VS Code, 64-bit edition (version 1.80.1)
[✓] Connected device (1 available)
[✓] Network resources

• No issues found!

Additional context Code used:


import 'package:device_calendar/device_calendar.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:timezone/timezone.dart' as tz;

class CalendarService {
  void addTaskToCalendar(
    String taskTitle,
    DateTime taskDate,
    bool allDay,
  ) async {
    final deviceCalendarPlugin = DeviceCalendarPlugin();

    final result = await deviceCalendarPlugin.createCalendar(
      "Tasks",
      localAccountName: "Todoify",
    );

    Event event = Event(
      result.data,
      title: taskTitle,
      allDay: allDay,
      start: tz.TZDateTime.from(
        taskDate,
        tz.local,
      ),
      end: tz.TZDateTime.from(
        taskDate,
        tz.local,
      ),
    );

    final createEvent = await deviceCalendarPlugin.createOrUpdateEvent(event);
    if (createEvent!.isSuccess) {
      Fluttertoast.showToast(msg: "Task successfully added");
    } else {
      print(createEvent.errors.first.errorCode);
      print(createEvent.errors.first.errorMessage);
    }
  }
}
milindgoel15 commented 11 months ago

Another thing, more like feature enhancement:

Possibility to add events using intent which opens the calendar app to add the event/task/anything.