I want to add recurrenceRule for my schedule but this error happened:
======== Exception caught by widgets library =======================================================
The following assertion was thrown building LayoutBuilder:
Invalid weekly recurrence rule
'package:syncfusion_flutter_calendar/src/calendar/appointment_engine/recurrence_helper.dart':
Failed assertion: line 150 pos 16: 'weeklyByDayPos != -1'
The relevant error-causing widget was:
SfCalendar file:///C:/Users/Iman/Projects/sistem-akademik/lib/schedule_screen.dart:99:26
When the exception was thrown, this was the stack:
#2 RecurrenceHelper.getRecurrenceDateTimeCollection (package:syncfusion_flutter_calendar/src/calendar/appointment_engine/recurrence_helper.dart:150:16)
#3 AppointmentHelper._getRecurrenceAppointments (package:syncfusion_flutter_calendar/src/calendar/appointment_engine/appointment_helper.dart:1424:41)
#4 AppointmentHelper.getVisibleAppointments (package:syncfusion_flutter_calendar/src/calendar/appointment_engine/appointment_helper.dart:1219:7)
#5 _SfCalendarState._getInitialScrollPosition (package:syncfusion_flutter_calendar/src/calendar/sfcalendar.dart:5387:27)
#6 _SfCalendarState.addAgenda (package:syncfusion_flutter_calendar/src/calendar/sfcalendar.dart:5228:46)
This is my snippet code:
MeetingDataSource getCalendarDataSource() {
List<Appointment> appointments = <Appointment>[];
appointments.add(Appointment(
from: DateTime(2021, 01, 25, 07, 00),
to: DateTime(2021, 01, 25, 07, 00).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Pendidikan Anti Korupsi',
courseCode: 'KU4079',
lecturer: 'Dr. Wahid',
classroom: '02',
background: Colors.red));
appointments.add(Appointment(
from: DateTime(2021, 01, 25, 10, 00),
to: DateTime(2021, 01, 25, 10, 00).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Pengembangan Aplikasi pada Platform Khusus',
courseCode: 'IF3210',
lecturer: 'Budi, S.T. M.T.',
classroom: '01',
background: Colors.blue));
appointments.add(Appointment(
from: DateTime(2021, 01, 25, 13, 00),
to: DateTime(2021, 01, 25, 13, 00).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Grafika Komputer',
courseCode: 'IF3260',
lecturer: 'Tia, S.T. M.T.',
classroom: '02',
background: Colors.green));
appointments.add(Appointment(
from: DateTime(2021, 01, 25, 16, 00),
to: DateTime(2021, 01, 25, 16, 00).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Sistem Paralel dan Terdistribusi',
courseCode: 'IF3230',
lecturer: 'Dr. Bambang, M.Sc.',
classroom: '03',
background: Colors.purple));
appointments.add(Appointment(from: DateTime(2021, 01, 26, 08, 00),
to: DateTime(2021, 01, 26, 08, 00).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Agama dan Etika Islam',
courseCode: 'KU2061',
lecturer: 'Dr. Susilo, M.Ag.',
classroom: '01',
background: Colors.deepPurple));
appointments.add(Appointment(
from: DateTime(2021, 01, 26, 11, 00),
to: DateTime(2021, 01, 26, 11, 00).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Pembelajaran Mesin',
courseCode: 'IF3270',
lecturer: 'Dr. Bambang',
classroom: '01',
background: Colors.lightBlueAccent));
appointments.add(Appointment(
from: DateTime(2021, 01, 26, 13, 30),
to: DateTime(2021, 01, 26, 13, 30).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Socio-informatika dan Profesionalisme',
courseCode: 'IF3280',
lecturer: 'Reno, Ph.D.',
classroom: '03',
background: Colors.deepOrange));
appointments.add(Appointment(
from: DateTime(2021, 01, 27, 07, 00),
to: DateTime(2021, 01, 27, 07, 00).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Proyek Perangkat Lunak',
courseCode: 'IF3250',
lecturer: 'Dr. Sutrisno, S.T, M.T.',
classroom: '01',
background: Colors.blueGrey));
appointments.add(Appointment(
from: DateTime(2021, 01, 27, 15, 30),
to: DateTime(2021, 01, 27, 15, 30).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Grafika Komputer',
courseCode: 'IF3260',
lecturer: 'Tia, S.T. M.T.',
classroom: '02',
background: Colors.green));
appointments.add(Appointment(
from: DateTime(2021, 01, 28, 08, 30),
to: DateTime(2021, 01, 28, 08, 30).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Pengembangan Aplikasi pada Platform Khusus',
courseCode: 'IF3210',
lecturer: 'Budi, S.T. M.T.',
classroom: '01',
background: Colors.blue));
appointments.add(Appointment(
from: DateTime(2021, 01, 28, 13, 30),
to: DateTime(2021, 01, 28, 13, 30).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Proyek Perangkat Lunak',
courseCode: 'IF3250',
lecturer: 'Dr. Sutrisno, S.T, M.T.',
classroom: '01',
background: Colors.blueGrey));
appointments.add(Appointment(
from: DateTime(2021, 01, 28, 16, 00),
to: DateTime(2021, 01, 28, 16, 00).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Sistem Paralel dan Terdistribusi',
courseCode: 'IF3230',
lecturer: 'Dr. Bambang, M.Sc.',
classroom: '03',
background: Colors.purple));
appointments.add(Appointment(
from: DateTime(2021, 01, 29, 07, 30),
to: DateTime(2021, 01, 29, 07, 30).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Proyek Perangkat Lunak',
courseCode: 'IF3250',
lecturer: 'Dr. Sutrisno, S.T, M.T.',
classroom: '01',
background: Colors.blueGrey));
appointments.add(Appointment(
from: DateTime(2021, 01, 29, 16, 00),
to: DateTime(2021, 01, 29, 16, 00).add(const Duration(hours: 2)),
recurrenceRule: 'FREQ=WEEKLY;COUNT=15',
eventName: 'Socio-informatika dan Profesionalisme',
courseCode: 'IF3280',
lecturer: 'Reno, Ph.D.',
classroom: '03',
background: Colors.deepOrange));
return MeetingDataSource(appointments);
|
MeetingDataSource _getCalendarDataSource() { List<Meeting> meetings = <Meeting>[]; meetings.add(Meeting( eventName: 'meeting', from: DateTime(2021, 06, 29, 10), to: DateTime(2021, 06, 29, 12), background: Colors.green, isAllDay: false, recurrenceRule: 'FREQ=WEEKLY;BYDAY=SU;COUNT=15', )); return MeetingDataSource(meetings); } |
Thank you very much for your answer. It's worked.
Hi, it looks like the problem is still there.
weeklyByDayPos could be empty in case of FREQ=WEEKLY;COUNT=2 which is valid rrule
Yes I have seen the ticket on the github where you recommend create your own logic to fix that issue. The simple solution directly in the package is about line with the assertion where you simply check whether position is -1 and then parse day in week as integer value from the recurrenceStartDate.
Hi Michal Charvat,
As per the iCalendar specification, FREQ=WEEKLY;COUNT=2 is valid. However, in SfCalendar, weekly recurrence rules require a BYDAY value to specify which weekday the event repeats on. Without it, the calendar does not automatically detect the weekday from the start date and throws an assertion error.
For example, if the recurrence rule is FREQ=WEEKLY;COUNT=2;BYDAY=MO, the event will start on a Monday.
Regards,
Praveen Balu.
Hi Praveen, as I mentioned above, there is simple workaround which would fix the issue and does not force programmers to create workarounds outside the calendar. Instead of raising the exception you can easily parse the recurrenceStartDate and append the BYDAY string to RRULE if it does not exist
Hi Michal Charvat,
To improve “WEEKLY” recurrence rule in SfCalendar as per your request, we have already logged a feature request for it in our feedback portal.
We will prioritize the features of every release based on demand and priority. So, this feature will be available in any of our upcoming releases. You can also track the status of the feature using the feedback link below.
FR link - Enhance the recurrence rule, similar to Google Calendar’s in Flutter | Feedback Portal
Regards,
Praveen Balu.