Category / Section
How to use a negative value for BYSETPOS in a RRule of recurrence appointment in the Flutter Calendar
2 mins 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.
This article demonstrates how to display appointments on particular days of the last week and the week before last of each month in the Flutter Event Calendar by using the BYSETPOS values of -1 and -2.
In this example, we'll create a recurrence appointment that appears on Thursday of either the last week or the week before last of each month.
First, initialize the state with default values:
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); }