We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Cannot click on a recurring event

Hello,

I have a functioning application that is for event scheduling and everything is working great - thank you Syncfusion team!

I'm now trying to add recurring event functionality and cannot click on anything that is created using recurrence.

I am using version 20.4.52 of the syncfusion_flutter_calendar.

Once the recurring event is created is shows up on the calendar which is great (see below):

When I click on the recurring event, I get the following error message:

"Error: Expected a value of type 'SchedulerEvent', but got one of type 'Appointment'"

My custom event class is called 'SchedulerEvent' and has been working great so far, but I'm never seen this error before.

I did some research and thought that perhaps I needed to implement the 'convertAppointmentToObject' override within my CalendarDataSource class (although it's been working fine without this override for several months).

My datasource class is like this:

import 'dart:ui';
import 'package:sandbox_web/models/scheduler_event.dart';
import 'package:sandbox_web/scheduler_utils.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';

/// An object to set the appointment collection data source to something the calendar can understand,
/// which is used to map the custom appointment data to the calendar appointment, and
/// allows to add, remove or reset the appointment collection.
class SchedulerEventsDataSource extends CalendarDataSource {
/// Creates a meeting data source, which used to set the appointment
/// collection to the calendar in this example, this is called by this line of code below:
/// dataSource: SchedulerEventsDataSource(_getDataSource())
/// CTOR
SchedulerEventsDataSource(List<SchedulerEvent> eventsListFromFireStore) {
/// this is where the translation happens that creates a 'Scheduler event'
/// and then assigns it to an 'Appointments' class
/// this is the class that the Calendar is ready to work with
appointments = eventsListFromFireStore;
}

/// overrides
@override
DateTime getStartTime(int index) => appointments![index].from;

@override
DateTime getEndTime(int index) => appointments![index].to;

@override
bool isAllDay(int index) => appointments![index].isAllDay;

@override
String getSubject(int index) => appointments![index].title;

@override
Color getColor(int index) => SchedulerUtils.getBackgroundColorFromFirestore(appointments![index].background);

@override
String? getRecurrenceRule(int index) => appointments![index].recurrenceRule;

@override
SchedulerEvent? convertAppointmentToObject(SchedulerEvent? customData, Appointment appointment){
return SchedulerEvent(
from: appointment.startTime,
to: appointment.endTime,
title: appointment.subject,
background: appointment.color.toString(),
isAllDay: appointment.isAllDay,
recurrenceRule: appointment.recurrenceRule,
);
}
}


The error that I'm getting when I try to implement this override is as follows:

'SchedulerEventsDataSource.convertAppointmentToObject' ('SchedulerEvent? Function(SchedulerEvent?, Appointment)') isn't a valid override of 'CalendarDataSource.convertAppointmentToObject' ('Object? Function(Object?, Appointment)').


Has anyone run into this issue with a custom appointment event and were you able to resolve?


7 Replies

IR Indumathi Ravichandran Syncfusion Team April 20, 2023 07:15 AM UTC

Martin,


As per the shared information, we have checked the issue of “Unable to click the recurrence appointment in the Flutter Calendar” and it was working fine as expected from our end. We have checked with custom appointment with recurrence, it was working fine. We have attached the tested sample and output video for the same.


Code snippet for implementing override method (convertAppointmentToObject):


class MeetingDataSource extends CalendarDataSource<Meeting> {
MeetingDataSource(List<Meeting> source) {
appointments = source;
}

@override
DateTime getStartTime(int index) {
return appointments![index].from;
}

@override
DateTime getEndTime(int index) {
return appointments![index].to;
}

@override
Object? getId(int index) {
return appointments![index].id;
}

@override
Object? getRecurrenceId(int index) {
return appointments![index].recurrenceId as Object?;
}

@override
Color getColor(int index) {
return appointments![index].background as Color;
}

@override
List<DateTime>? getRecurrenceExceptionDates(int index) {
return appointments![index].exceptionDates as List<DateTime>?;
}

@override
String? getRecurrenceRule(int index) {
return appointments![index].recurrenceRule;
}

@override
String getSubject(int index) {
return appointments![index].eventName as String;
}

@override
bool isAllDay(int index) {
return appointments![index].isAllDay as bool;
}

@override
Meeting? convertAppointmentToObject(
Meeting? customData, Appointment appointment) {
// TODO: implement convertAppointmentToObject
return Meeting(
from: appointment.startTime,
to: appointment.endTime,
eventName: appointment.subject,
background: appointment.color,
isAllDay: appointment.isAllDay,
id: appointment.id,
recurrenceRule: appointment.recurrenceRule,
recurrenceId: appointment.recurrenceId,
exceptionDates: appointment.recurrenceExceptionDates);
}
}


Please check the sample once and let us know still if you are facing same issue? If not please modify the sample based on your scenario and revert us with more details.


Sample and Video link:


Attachment: SampleandVideo_f43ea9b6.zip


MA Martin April 20, 2023 11:31 PM UTC

Thanks for the sample - the missing part was the definition of the Type for the CalendarDataSource. In my case I needed to modify CalendarDataSource to become CalendarDataSource<SchedulerEvent>. This does not seem to cause any problems when the overrides are used UNTIL the convertAppointmentToObject  is used.


Perhaps that should be documented?



MA Martin April 21, 2023 01:57 AM UTC

Ok, now there seems to be a new problem. When clicking on the recurring event in the Calendar, it seems to have lost all of the Custom Business Object Properties that it should have.

I noticed on this page : https://help.syncfusion.com/flutter/calendar/callbacks#calendar-tap-callback 

It states this "For recurrence appointment, the tap details will always return as Appointment, even for the custom business object."

How do I get around this issue because I have logic that requires many of the additional object properties that are part of my custom object?



MS Muniappan Subramanian Syncfusion Team April 21, 2023 10:29 AM UTC

Martin,


According to the shared details, we have checked your requirement. You can get the custom business object type by overriding the convertAppointmentToObject() method from the CalendarDataSource. We have checked the tapped event and the Custom object data was shown. We have attached the output for your reference.


Please refer to our UG documentation to get more information on getting the business object data in the calendar,

https://help.syncfusion.com/flutter/calendar/appointments#get-the-business-object-data


If the shared information doesn’t meet your requirement kindly revert us with more information, it will be helpful for us to provide you with a better solution.


Attachment: output_a0941dd2.zip


MA Martin April 21, 2023 04:20 PM UTC

Muniappan, Thank you for the response - however, convertAppointmentToObject is not passing the correct custom business object when using onTap. There are many additional properties that are not part of the Appointment object that are missing for recurring events only. Non-recurring events are not impacted by this in any way.

I will try to illustrate what I'm seeing with images from both the debugger and the Firebase console.

The image error_recurring_1 shows a non-recurring event in the debugger with all of the extended properties - this is the expected behavior.

The image error_recurring_2 shows the corresponding data in Firestore - this data is correct.

The image error_recurring_3 shows a recurring event in the debugger with several fields set as the default values - this is not the expected behavior

The image error_recurring_4 shows the corresponding data in Firestore - the data is correct there but not correct in the debugger and later in the way it is displayed in UI.

The image error_recurring_5 and image error_recurring_6 show another field (in this case it is called "createdBy" and hold a String value) where the data is missing in the onTap event for the SfCalendar but it is not missing in Firestore


Thank you



Attachment: error_recurring_images_bf4bf9d2.zip


IR Indumathi Ravichandran Syncfusion Team April 24, 2023 12:20 PM UTC

Martin,


Regarding Query: There are many additional properties that are not part of the Appointment object that are missing for recurring events only.


By using the instance of the custom appointment
in the covertAppointmentToObject() method you can get the additional properties value through onTap callback of the Flutter Calendar. We have attached the code snippet for the same.


Code snippet:


 

class Meeting {
  Meeting(
      {required this.from,
      required this.to,
      this.id,
      this.recurrenceId,
      this.eventName = '',
      this.isAllDay = false,
      this.background,
      this.exceptionDates,
      this.recurrenceRule,
      this.department});

  DateTime from;
  DateTime to;
  Object? id;
  Object? recurrenceId;
  String eventName;
  bool isAllDay;
  Color? background;
  String? fromZone;
  String? toZone;
  String? recurrenceRule;
  List<DateTime>? exceptionDates;
  String? department;
}
 
appointments.add(Meeting(
    from: DateTime.now().add(const Duration(hours: 4, days: -1)),
    to: DateTime.now().add(const Duration(hours: 5, days: -1)),
    eventName: 'Recurrence appointment',
    id: '04',
    background: Colors.yellow,
    recurrenceRule: 'FREQ=DAILY;COUNT=20',
    department: "development"));

 

@override
Meeting? convertAppointmentToObject(
Meeting? customData, Appointment appointment) {
// TODO: implement convertAppointmentToObject
return Meeting(
from: appointment.startTime,
to: appointment.endTime,
eventName: appointment.subject,
background: appointment.color,
isAllDay: appointment.isAllDay,
id: appointment.id,
recurrenceRule: appointment.recurrenceRule,
recurrenceId: appointment.recurrenceId,
exceptionDates: appointment.recurrenceExceptionDates,
department: customData!.department);
}


Please check the sample once and share your concern.




Attachment: SampleandVideo_bd633d3c.zip


MA Martin April 25, 2023 05:32 AM UTC

Thank you Indumathi, that seems to have cleared things up. 

Have a great rest of the week.


-- Martin


Loader.
Up arrow icon