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,
);
}
}
'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?
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):
|
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:
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?
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?
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.
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
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:
@override |
Please check the sample once and share your concern.
Thank you Indumathi, that seems to have cleared things up.
Have a great rest of the week.
-- Martin