We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to integrate Event Calendar (SfCalendar) with date picker (SfDateRangePicker) in Flutter


In the Flutter Event Calendar, you can integrate the Calendar with DateRangePicker controls for required customization.

STEP 1: Inside the state, set the default values for the calendar and date range picker.

final CalendarController _calendarController = CalendarController();
final DateRangePickerController _dateRangePickerController = DateRangePickerController();

STEP 2: Hide the header and view header of the calendar and place the picker with single week and inside the column widget place the SfCalendar and SfDateRangePicker.

child: Column(
  children: [
    Container(
      height: 100,
      child: SfDateRangePicker(
        controller: _dateRangePickerController,
        showNavigationArrow: true,
        allowViewNavigation: false,
        monthViewSettings: DateRangePickerMonthViewSettings(
            numberOfWeeksInView: 1),
        onSelectionChanged: selectionChanged,
      ),
    ),
    Expanded(
      child: SfCalendar(
        headerHeight: 0,
        controller: _calendarController,
        viewHeaderHeight: 0,
        dataSource: _getCalendarDataSource(),
        onViewChanged: viewChanged,
      ),
    ),
  ],
),

STEP 3: Using the onSelectionChanged callback of the Flutter date range picker control you can move the calendar view and the picker selection will be applied based on the onViewChanged callback of the Flutter event calendar.

void viewChanged(ViewChangedDetails viewChangedDetails) {
  SchedulerBinding.instance!.addPostFrameCallback((timeStamp) {
    _dateRangePickerController.selectedDate =
    viewChangedDetails.visibleDates[0];
    _dateRangePickerController.displayDate =
    viewChangedDetails.visibleDates[0];
  });
}
void selectionChanged(DateRangePickerSelectionChangedArgs args) {
  SchedulerBinding.instance!.addPostFrameCallback((timeStamp) {
    _calendarController.displayDate = args.value;
  });
}

Screenshot

 

calendarpickergif

 

View sample in GitHub

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile