Failed assertion: line 150 pos 16: 'weeklyByDayPos != -1'

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);

7 Replies 1 reply marked as answer

IR Indumathi Ravichandran Syncfusion Team June 29, 2021 07:38 AM UTC

Hi Team, 
 
Thank you for contacting Syncfusion support. 
 
Based on the provided information, we have checked the mentioned issue “Exception occurred while using recurrence rule for appointments in Flutter Calendar” and we are unable to reproduce the mentioned exception from our end. For weekly recurrence appointment, you need to set the “BYDAY” property to recurring the events for that day. We have attached the code snippet for the same.  
 
Code snippet: 
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);
}
 
 
Also, we have prepared the simple sample for the same. Please find the sample from the link. 
 
 
Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us with following details, 
 
1.       Exception reproducing video. 
2.       Exception reproducing scenario. 
3.       Flutter Calendar package version. 
 
 It will be helpful for us to check on it and provide you solution at the earliest. 
 
Regards, 
Indumathi R 


Marked as answer

MD Mohamad Daffa replied to Indumathi Ravichandran June 29, 2021 09:40 AM UTC

Thank you very much for your answer. It's worked.



IR Indumathi Ravichandran Syncfusion Team June 29, 2021 11:02 AM UTC

Hi Team, 
Thank you for the update. Please get in touch with us if you would require any further assistance. 
Regards, 
Indumathi R 



MC Michal Charvat October 7, 2025 03:10 PM UTC

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.



PB Praveen Balu Syncfusion Team October 8, 2025 10:27 AM UTC

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.



MC Michal Charvat replied to Praveen Balu October 13, 2025 10:31 AM UTC

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



PB Praveen Balu Syncfusion Team October 14, 2025 10:00 AM UTC

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.


Loader.
Up arrow icon