CalendarDataSource class

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.

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(
     {this.from,
     this.to,
     this.title,
     this.isAllDay,
     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

Constructors

CalendarDataSource()

Properties

appointments List
Tha collection of appointments to be rendered on SfCalendar. [...]
read / write
hashCode int
The hash code for this object. [...]
read-only, inherited
resources List<CalendarResource>
The collection of resource to be displayed in the timeline views of SfCalendar. [...]
read / write
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

addListener(CalendarDataSourceCallback listener) → void
Calls the listener every time the collection in the CalendarDataSource changed [...]
inherited
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). [...]
@mustCallSuper, 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. [...]
getLocation(int index) String
Maps the custom appointments location to the Appointment. [...]
getNotes(int index) String
Maps the custom appointments notes to the Appointment. [...]
getRecurrenceExceptionDates(int index) List<DateTime>
Maps the custom appointments recurrenceExceptionDates 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. [...]
isAllDay(int index) bool
Maps the custom appointments isAllDay to the Appointment. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent 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
toString() String
Returns a string representation of this object.
inherited

Operators

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