Articles in this section

How to use id, recurrenceId, appointment Type in the Flutter Calendar (SfCalendar)?

In the Flutter calendar, the Appointment class has an id, recurrenceId, and appointmentType support.

 

Appointment types

The appointmentType property specifies the appointment type, which distinguishes appointments based on their functionality. This is read-only property with the following types: normal, pattern, occurrence, and changedOccurence.

 

Id

Id can be set for all the appointment types where the internally created occurrence appointment will have the same id value as the pattern appointment. The exception appointment should have a different id value compared to the pattern appointment. But the recurrenceId of the exception appointment should match the id of its pattern appointment.

 

recurrenceId

The recurrenceId of the exception appointment and the id of the pattern appointment should be the same. The recurrenceId should be specified only for exception appointments. It is not required for occurrence and normal appointments.

 

STEP 1: Set an unique id for the appointment like the following code snippet.

final Appointment normalAppointment = Appointment(
  startTime: DateTime(2021, 07, 11, 10),
  endTime: DateTime(2021, 07, 11, 12),
  subject: 'Planning',
  id: '01',
  color: Colors.green,
  recurrenceExceptionDates: <DateTime>[exceptionDate],
);
appointments.add(normalAppointment);
final Appointment recurrenceAppointment = Appointment(
  startTime: DateTime(2021, 07, 12, 10),
  endTime: DateTime(2021, 07, 12, 12),
  subject: 'Scrum meeting',
  id: '02',
  recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=10',
  color: Colors.purple,
  recurrenceExceptionDates: <DateTime>[exceptionDate],
);
appointments.add(recurrenceAppointment);

 

STEP 2: Handle the changed occurrence appointment by using the recurrenceId property.

final Appointment exceptionAppointment = Appointment(
    startTime: exceptionDate.add(const Duration(hours: 14)),
    endTime: exceptionDate.add(const Duration(hours: 15)),
    subject: 'Meeting',
    id: '03',
    color: Colors.pinkAccent,
    recurrenceId: recurrenceAppointment.id);
appointments.add(exceptionAppointment);

 

STEP 3: Display the tapped appointment details in the Alert dialog window.

child: SfCalendar(
  dataSource: _getDataSource(),
  view: CalendarView.week,
  onTap: calendarTapped,
),
 
void calendarTapped(CalendarTapDetails calendarTapDetails) {
  if (calendarTapDetails.targetElement == CalendarElement.appointment) {
    _showDialog(calendarTapDetails);
  }
}
 
_showDialog(CalendarTapDetails details) async {
  Appointment appointment = details.appointments![0];
  await showDialog(
    context: context,
    builder: (BuildContext context) {
      return new AlertDialog(
        title: Container(
          child: Text("Appointment Details"),
        ),
        contentPadding: const EdgeInsets.all(16.0),
        content: Text("Subject: " +
            appointment.subject +
            "\nId: " +
            appointment.id.toString() +
            "\nRecurrenceId: " +
            appointment.recurrenceId.toString()+ "\nAppointment type: "+appointment.appointmentType.toString()),
        actions: <Widget>[
          new TextButton(
              child: const Text('OK'),
              onPressed: () {
                Navigator.pop(context);
              })
        ],
      );
    },
  );
}

View the GitHub sample here

Flutter Calendar id, recurrenceId

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied