Set currentDate on Calendar

Hello,

I am trying out the Calendar and it looks great so far, however, I am running into a problem: I'm trying to display the calendar with a Day/Week/Month toggle (this works fine), but also another field with a Date picker so you can go to a different date quickly in the Calendar. This field needs to be up to date with the currentDate in the Calendar. 
Using the onViewChanged method I can update the field with the date shown in the Calendar, but it doesn't work the other way around (_currentDate seems to be a private field). When I set the initialDisplayValue to that same value, strange stuff starts to happen when I swipe the Calendar (it sometimes skips a day).

I have a DateFilterModel which has a currentDate field, which is used for the DatePicker. Both the DatePicker widget and the Calendar use this DateFilterModel using a Provider. This is my build method, and the strange stuff starts when I set initalDisplayDate: _calendarModel.currentDate:

Widget build(BuildContext context) {
_calendarModel = Provider.of<DateFilterModel>(context);

//if (currentDate != _calendarModel.currentDate) currentDate = _calendarModel.currentDate;

return Stack(
children: <Widget>[
Container(
child: SfCalendar(
initialDisplayDate: currentDate,
view: _modes[mode],
todayHighlightColor: ColorConstants.secondary,
timeSlotViewSettings: TimeSlotViewSettings (timeFormat: StringConstants.of(context).timeFormat),
onViewChanged: (details) {
List<DateTime> dates = details.visibleDates;
_calendarModel.currentDate = dates.first;
},
),
),
_createHeaderRow(context),
],
);
}
Any ideas what I am doing wrong here?

Thanks!

3 Replies

IR Indumathi Ravichandran Syncfusion Team February 14, 2020 10:50 AM UTC

Hi Stijn Melis,    
   
Thank you for contacting Syncfusion support.   
   
Based on the provided information, we suspect that your requirement is to update the `initialDisplayDate` of `SfCalendar` when selecting a date from DatePicker and updating DatePicker date from calendar current view dates and it can be achieved by using OnViewChanged callback of the calendar and showDatePicker widget. We have prepared the simple sample for the same. Please find the sample from following link.   
  
   
 
We hope that this helps you. Please let us know if you need further assistance on this.   
   
Regards,   
Indumathi R   



SM Stijn Melis February 14, 2020 11:41 AM UTC

Hi,

I had a look, tried it out and it works. Thanks a lot!

Apparently the problem was that I tried to keep everything in 1 DateTime variable for both the DatePicker and the Calendar.

Thanks again!

Cheers,

Stijn


IR Indumathi Ravichandran Syncfusion Team February 14, 2020 11:48 AM UTC

Hi Stijn Melis,    
 
Thank you for the update. 
 
We are glad to know that provided solution meet your requirement. Please get in touch with us if you would require any further assistance. 
 
Regards, 
Indumathi R 


Loader.
Up arrow icon