Category / Section
How to get the recurrence properties from RRule in the Flutter Calendar
1 min read
In the Flutter Event Calendar, you can retrieve recurrence rule properties using the parseRRule method.
Inside the state initialize the default values for calendar.
String _recurrenceRule = 'FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,WE;UNTIL=20210810'; DateTime _startTime = DateTime.now();
use the onPressed callback of the RaisedButton to show the alert dialog and get the recurrence properties of the recurrence rule.
child: Column(
children: [
Center(
child: new RaisedButton(
onPressed: _showDialog,
child: new Text("Get recurrence rule"),
),
),
Expanded(
child: SfCalendar(
view: CalendarView.month,
dataSource: _getCalendarDataSource(),
))
],
),
_AppointmentDataSource _getCalendarDataSource() {
List<Appointment> appointments = <Appointment>[];
appointments.add(Appointment(
startTime: _startTime,
endTime: _startTime.add(Duration(hours: 1)),
subject: 'Meeting',
color: Colors.blue,
recurrenceRule: _recurrenceRule));
return _AppointmentDataSource(appointments);
}
In this alert dialog, retrieve the recurrence properties by using the parseRRule method of the calendar and displathy the recurrence properties in alert window.
_showDialog() async {
RecurrenceProperties _recurrenceProperties =
SfCalendar.parseRRule(_recurrenceRule, _startTime);
await showDialog(
context: context,
// ignore: deprecated_member_use
builder: (BuildContext context) {return AlertDialog(
contentPadding: const EdgeInsets.all(16.0),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Type:' + _recurrenceProperties.recurrenceType.toString(),
),
Text(
'Count:' + _recurrenceProperties.recurrenceCount.toString(),
),
Text(
'StartDate:' + _recurrenceProperties.startDate.toString(),
),
Text(
'EndDate:' + _recurrenceProperties.endDate.toString(),
),
Text(
'Interval: ' + _recurrenceProperties.interval.toString(),
),
Text(
'Range:' + _recurrenceProperties.recurrenceRange.toString(),
),
Text(
'WeekDays:' + _recurrenceProperties.weekDays.toString(),
),
Text(
'Week:' + _recurrenceProperties.week.toString(),
),
Text(
'DayOfMonth:' + _recurrenceProperties.dayOfMonth.toString(),
),
Text(
'DayOfWeek:' + _recurrenceProperties.dayOfWeek.toString(),
),
Text(
'Month:' + _recurrenceProperties.month.toString(),
),
],
),
actions: <Widget>[
new FlatButton(
child: const Text('CANCEL'),
onPressed: () {
Navigator.pop(context);
}),
new FlatButton(
child: const Text('OK'),
onPressed: () {
Navigator.pop(context);
})
],
);},
);
}
|
