dataSource property Null safety

CalendarDataSource? dataSource
final

Used to set the Appointment or custom event collection through the CalendarDataSource class.

If it is not null the collection of appointments set to the CalendarDataSource.appointments property will be set to SfCalendar and rendered on view.

Defaults to null.

see also: CalendarDataSource


Widget build(BuildContext context) {
   return Container(
     child: SfCalendar(
       view: CalendarView.week,
       dataSource: _getCalendarDataSource(),
       timeSlotViewSettings: TimeSlotViewSettings(
           timeTextStyle: TextStyle(
               fontSize: 12,
               fontWeight: FontWeight.w500,
               color: Colors.blue,
               fontStyle: FontStyle.italic)
       ),
     ),
   );
 }

class DataSource extends CalendarDataSource {
 DataSource(List<Appointment> source) {
   appointments = source;
 }
}

 DataSource _getCalendarDataSource() {
   List<Appointment> appointments = <Appointment>[];
   appointments.add(Appointment(
     startTime: DateTime.now(),
     endTime: DateTime.now().add(Duration(hours: 2)),
     isAllDay: true,
     subject: 'Meeting',
     color: Colors.blue,
     startTimeZone: '',
     endTimeZone: '',
   ));

   return DataSource(appointments);
 }

Implementation

final CalendarDataSource? dataSource;