CalendarDataSource<T extends Object?> class abstract

An object that maintains the data source for SfCalendar.

Allows to map the custom appointments to the Appointment and set the appointments collection to the SfCalendar to render the appointments on view.

Allows to add and remove an Appointment from the collection and also allows to reset the appointment collection for SfCalendar.

Note: This method must be implemented to get the data with business object type when drag and drop or appointment resizing enabled.

See also:

Widget build(BuildContext context) {
  return Container(
     child: SfCalendar(
       view: CalendarView.day,
       dataSource: _getCalendarDataSource(),
     ),
   );
 }

class MeetingDataSource extends CalendarDataSource {
 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
 Color getColor(int index) {
   return appointments![index].background;
 }

 @override
 String getEndTimeZone(int index) {
   return appointments![index].toZone;
 }

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

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

 @override
 String getStartTimeZone(int index) {
   return appointments![index].fromZone;
 }

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

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

class _Meeting {
 _Meeting(
     {required this.from,
     required this.to,
     this.title='',
     this.isAllDay=false,
     required this.background,
     this.fromZone='',
     this.toZone='',
     this.exceptionDates,
     this.recurrenceRule=''});
 DateTime from;
 DateTime to;
 String title;
 bool isAllDay;
 Color background;
 String fromZone;
 String toZone;
 String recurrenceRule;
 List<DateTime>? exceptionDates;
}

final DateTime date = DateTime.now();
 MeetingDataSource _getCalendarDataSource() {
   List<_Meeting> appointments = <_Meeting>[];
   appointments.add(_Meeting(
    from: date,
    to: date.add(const Duration(hours: 1)),
    title: 'General Meeting',
    isAllDay: false,
    background: Colors.red,
    fromZone: '',
    toZone: '',
    recurrenceRule: '',
    exceptionDates: null
 ));

   return MeetingDataSource(appointments);
 }
Inheritance
Annotations

Constructors

CalendarDataSource()

Properties

appointments List?
Tha collection of appointments to be rendered on SfCalendar.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
resources List<CalendarResource>?
The collection of resource to be displayed in the timeline views of SfCalendar.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(CalendarDataSourceCallback listener) → void
Calls the listener every time the collection in the CalendarDataSource changed
inherited
convertAppointmentToObject(T customData, Appointment appointment) → T?
Converts the Appointment data to the custom business object data.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener and removeListener will throw after the object is disposed).
inherited
getColor(int index) Color
Maps the custom appointments color to the Appointment.
getEndTime(int index) DateTime
Maps the custom appointments end time to the Appointment.
getEndTimeZone(int index) String?
Maps the custom appointments end time zone to the Appointment.
getId(int index) Object?
Maps the custom appointments id to the Appointment.
getLocation(int index) String?
Maps the custom appointments location to the Appointment.
getNotes(int index) String?
Maps the custom appointments notes to the Appointment.
getOccurrenceAppointment(Object? patternAppointment, DateTime date, String calendarTimeZone) Appointment?
Returns the occurrence appointment for the given pattern appointment at the specified date.
getPatternAppointment(Object? occurrenceAppointment, String calendarTimeZone) Object?
Returns the Pattern appointment for the provided occurrence appointment.
getRecurrenceExceptionDates(int index) List<DateTime>?
Maps the custom appointments recurrenceExceptionDates to the Appointment
getRecurrenceId(int index) Object?
Maps the custom appointments recurrence id to the Appointment.
getRecurrenceRule(int index) String?
Maps the custom appointments recurrence rule to the Appointment.
getResourceIds(int index) List<Object>?
Maps the custom appointment resource ids to the Appointment resource ids.
getStartTime(int index) DateTime
Maps the custom appointments start time to the Appointment.
getStartTimeZone(int index) String?
Maps the custom appointments start time zone to the Appointment.
getSubject(int index) String
Maps the custom appointments subject to the Appointment.
getVisibleAppointments(DateTime startDate, String calendarTimeZone, [DateTime? endDate]) List<Appointment>
Returns the appointments in the specified date range.
handleLoadMore(DateTime startDate, DateTime endDate) Future<void>
Called when loadMoreAppointments function is called from the loadMoreWidgetBuilder. Call the notifyListeners to notify the calendar for data source changes.
isAllDay(int index) bool
Maps the custom appointments isAllDay to the Appointment.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners(CalendarDataSourceAction type, List data) → void
Call all the registered listeners.
inherited
removeListener(CalendarDataSourceCallback listener) → void
remove the listener used for notify the data source changes.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited