Hello,
When I open the calendar with date x for the first time it draws appointment in correct way:
but when I open the same date for the second time one appointment overlaps another:
It looks like the calendar component holds appointment data inside the component and this causes the issue because from what I see the appointments are drawn incorrectly right after opening the screen and stays incorrectly after data reload:
I can see the same behavior on week and work week views.
My code looks here:
SfCalendar _createCalendar() {
return SfCalendar(
view: widget._calendarView,
//controller: _calendarController,
firstDayOfWeek: 1,
showDatePickerButton: true,
allowViewNavigation: true,
initialDisplayDate: widget._initialDate,
dataSource: TimetableDataSource([]),
loadMoreWidgetBuilder: (context, loadMoreAppointments) {
return FutureBuilder<void>(
future: loadMoreAppointments(),
builder: (context, snapShot) {
return const LoadingIndicator();
},
);
},
// appointmentBuilder: (context, calendarAppointmentDetails) {
// TimetableData timetableCellData = calendarAppointmentDetails.appointments.first;
// CellStyle cellStyle = CellStyle(timetableCellData);
//
// if (_calendarController.view == CalendarView.day) {
// return _buildDailyLesson(timetableCellData, cellStyle, _calendarController.view!);
// }
// return _buildWeeklyLesson(timetableCellData, cellStyle, _calendarController.view!);
// },
allowedViews: const[CalendarView.day, CalendarView.workWeek, CalendarView.week, CalendarView.month],
monthViewSettings: const MonthViewSettings(showAgenda: true),
showCurrentTimeIndicator: true,
showWeekNumber: true,
timeSlotViewSettings: const TimeSlotViewSettings(
timeIntervalHeight: 50,
timeTextStyle: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 14),
timeFormat: DateFormat.HOUR24,
startHour: 7,
endHour: 18,
nonWorkingDays:[DateTime.saturday, DateTime.sunday]),
);
}
In TimetableDataSource I override the handleLoadMore
@override
Future<void> handleLoadMore(DateTime startDate, DateTime endDate) async {
ListtimetableElements = await timetableService.getTimetableElements(startDate, endDate);
for (final TimetableData timetableElement in timetableElements) {
if (appointments!.contains(timetableElement)) {
continue;
}
appointments!.add(timetableElement);
}
notifyListeners(CalendarDataSourceAction.add, appointments!);
}
Is it a bug in the component or have I implemented something incorrectly?
//EDIT My goal is to paginate data, I don't want to get a few years data and put it in the calendar but load data on view change.
Thank you in advance for help.
Szymon
Szymon.
As per the instruction we have followed to check the reported issue and we are unable to replicate the issue from our end. We have checked the scenarios of loading the appointments using HandleLoadmore in the calendar. We have prepared a simple sample, please find the attached sample and tested video for the same.
Additional information
SfCalendar version: 20.4.42
Please check our sample and let us know if you still facing the same issue. if not, please modify our sample and revert us back with the following details which would be helpful for us to check on it and provide you the solution as soon as possible,
Share the issue replicate video.
Share the calendar code snippets
Share the issue reproducible sample
Hello Muniappan Subramanian
Thank you for your help. I debugged your code and it helped me a lot.
It turned out that I made a mistake in handleLoadMore method.
My code was:
appointments!.add(timetableElement);
}
notifyListeners(CalendarDataSourceAction.add, appointments!);
but it should be:
meetings.add(timetableElement);
}
appointments!.addAll(meetings);
notifyListeners(CalendarDataSourceAction.add, meetings);
I was passing appointments to notifyListeners instaed of meeting. After opening a screen for the second time I was passing the same appointments instaed of the empty meetings list.
Best Regards
Szymon
We are glad that our solution meets your requirement. Please let us know if you need any further update. As always, we are happy to help you out.