0

I am creating a Flutter application where I want to create an calendar entry for an event. So far I am releasing only for Android phones. When I tap the button that creates the calendar entry, it is successful only on Samsung phones. I have tested on Xiaomi(Xiaomi T13 Pro, Xiaomi Note Mi 10 Lite), Pocophone, OnePlus, Samsung S22, Samsung Fold 3 and other phones. Only the Samsung phones were able to create the event successfully. My code is below. The function requestPermissions() succesfully requests and gets the permissions granted (if the user approves), though on Samsung phones, I can completely omit it and it will still work. On other phones it will print false even if I grant permissions.


void addEventToCalendar(String workshopName, String workshopLocation,
      String strDate, String strTimeFrom, String strTimeTo) async {
    requestPermissions();

    //Split the date from DD/MM/YYYY format into components
    List<String> dateParts = strDate.split('/');
    int day = int.parse(dateParts[0]);
    int month = int.parse(dateParts[1]);
    int year = int.parse(dateParts[2]);

    // Split the time string into components
    List<String> timeParts = strTimeFrom.split(':');
    int hour = int.parse(timeParts[0]);
    int minute = int.parse(timeParts[1]);

    //Create the DateTime From from the split components
    DateTime dateTimeFrom = DateTime(year, month, day, hour, minute);

    // Split the time string into components
    timeParts = strTimeTo.split(':');
    hour = int.parse(timeParts[0]);
    minute = int.parse(timeParts[1]);

    // Create the DateTime To object
    DateTime dateTimeTo = DateTime(year, month, day, hour, minute);

    final Event event = Event(
      title: workshopName,
      description: 'Reminder for your workshop',
      location: workshopLocation,
      startDate: dateTimeFrom,
      endDate: dateTimeTo,
      allDay: false,
    );

    bool result = await Add2Calendar.addEvent2Cal(event);
    print(result);
  } 

I have tried to use the device_calendar package but I got a message that the event was successfully created though this didn't reflect in the calendar.

On the samsung phones the default calendar is the Samsung calendar. I have downloaded Google calendar which is the default calendar for Xiaomi and OnePlus phones, and I was given the option to select which calendar to use when I tapped to add the event.

0

Browse other questions tagged or ask your own question.