getPatternAppointment method

Object? getPatternAppointment(
  1. Object? occurrenceAppointment,
  2. String calendarTimeZone
)

Returns the Pattern appointment for the provided occurrence appointment.

occurrenceAppointment - required - The occurrence appointment for which the Pattern appointment is obtained.


class MyAppState extends State<MyApp>{
  late CalendarController _calendarController;
  late _AppointmentDataSource _dataSource;
  late Appointment recurrenceApp;
  @override
  initState(){
    _calendarController = CalendarController();
    _dataSource = _getCalendarDataSource();
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SfCalendar(
          view: CalendarView.month,
          controller: _calendarController,
          dataSource: _dataSource,
          initialDisplayDate: DateTime(2020,11,27,9),
          onTap: (CalendarTapDetails details) {
            if(details.appointments!.isNotEmpty &&
                                            details.appointments != null){
              final dynamic occurrenceAppointment =
                                                details.appointments![0];
              final Appointment? patternAppointment =
              _dataSource.getPatternAppointment(
                               occurrenceAppointment, '') as Appointment?;
            }
          },
        ),
      ),
    );
  }
  _AppointmentDataSource _getCalendarDataSource() {
    List<Appointment> appointments = <Appointment>[];
    recurrenceApp = Appointment(
      startTime: DateTime(2020,11,27,9),
      endTime: DateTime(2020,11,27,9).add(Duration(hours: 2)),
      subject: 'Meeting',
      color: Colors.cyanAccent,
      startTimeZone: '',
      endTimeZone: '',
      recurrenceRule: 'FREQ=DAILY;INTERVAL=2;COUNT=5',
    );
    appointments.add(recurrenceApp);
    appointments.add(Appointment(
        startTime: DateTime(2020,11,28,5),
        endTime: DateTime(2020,11,30,7),
        subject: 'Discussion',
        color: Colors.orangeAccent,
        startTimeZone: '',
        endTimeZone: '',
        isAllDay: true
    ));
    return _AppointmentDataSource(appointments);
  }
}
class _AppointmentDataSource extends CalendarDataSource {
  _AppointmentDataSource(List<Appointment> source){
    appointments = source;
  }
}

Implementation

Object? getPatternAppointment(
    Object? occurrenceAppointment, String calendarTimeZone) {
  if (occurrenceAppointment == null) {
    return null;
  }
  final List<dynamic> occurrenceAppointmentColl = <dynamic>[
    occurrenceAppointment
  ];
  final List<CalendarAppointment> occurrenceAppointments =
      AppointmentHelper.generateCalendarAppointments(
          this, calendarTimeZone, occurrenceAppointmentColl);
  final CalendarAppointment occurrenceCalendarAppointment =
      occurrenceAppointments[0];
  if ((occurrenceCalendarAppointment.recurrenceRule == null ||
          occurrenceCalendarAppointment.recurrenceRule!.isEmpty) &&
      occurrenceCalendarAppointment.recurrenceId == null) {
    return null;
  }
  final List<CalendarAppointment> dataSourceAppointments =
      AppointmentHelper.generateCalendarAppointments(
          this, calendarTimeZone, appointments);

  for (int i = 0; i < dataSourceAppointments.length; i++) {
    final CalendarAppointment dataSourceAppointment =
        dataSourceAppointments[i];
    if ((dataSourceAppointment.id ==
            occurrenceCalendarAppointment.recurrenceId) ||
        (occurrenceCalendarAppointment.recurrenceId == null &&
            dataSourceAppointment.id == occurrenceCalendarAppointment.id)) {
      return dataSourceAppointment.data;
    }
  }
  return null;
}