Articles in this section
Category / Section

How to use a negative value for BYSETPOS in a RRule of recurrence appointment in the Flutter Calendar

1 min read

In the Flutter Event Calendar, show the appointments in a particular day of the last week and the week before last of the month by using the BYSETPOS value as -1 and -2.

Here the recurrence appointment is created on Thursday of the week before last.

In initState(), set the default values for calendar.

String _recurrenceRule = '';
 
class ScheduleExample extends State<RecurrenceAppointmentPosition> {
    List<String> _setPosition = <String>[
    'BYSETPOS -1',
    'BYSETPOS -2',
  ];

Based on the selected BYSETPOS, RRule is updated.

appBar: AppBar(
    title: Text("Select BYSETPOS"),
    actions: <Widget>[
      IconButton(icon: Icon(Icons.arrow_forward), onPressed: () {}),
      PopupMenuButton<String>(
        icon: Icon(Icons.party_mode),
        itemBuilder: (BuildContext context) {
          return _setPosition.map((String choice) {
            return PopupMenuItem<String>(
              value: choice,
              child: Text(choice),
            );
          }).toList();
        },
        onSelected: (String value) {
          setState(() {
            if (value == 'BYSETPOS -1') {
              _recurrenceRule = 'FREQ=MONTHLY;COUNT=10;BYDAY=TH;BYSETPOS=-1';
            } else if (value == 'BYSETPOS -2') {
              _recurrenceRule ='FREQ=MONTHLY;COUNT=10;BYDAY=TH;BYSETPOS=-2';
            }
          });
        },
      ),
    ],
  ),
    body: SfCalendar(
      view: CalendarView.month,
      dataSource: _getCalendarDataSource(),
    )
 
_AppointmentDataSource _getCalendarDataSource() {
  List<Appointment> appointments = <Appointment>[];
  appointments.add(Appointment(
      startTime: DateTime.now().add(Duration(hours: 1)),
      endTime: DateTime.now().add(Duration(hours: 2)),
      subject: 'Planning',
      color: Colors.orangeAccent,
      recurrenceRule: _recurrenceRule));
 
  return _AppointmentDataSource(appointments);
}

View sample in GitHub

Flutter calendar BYSETPOS

 

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