fluttercalendarmonthcalendar

How to create only month range picker using syncfusion_flutter_datepicker


I am trying to do month range picker, but it is not working. I want to select the month range like date range and not to show date. User is not allowed to change the date. let say if user select Jan till March then

start date will be 01-01-2024

end date will be 31-03-2024

here is my code.

 SfDateRangePicker(
              view: DateRangePickerView.month,
              selectionMode: DateRangePickerSelectionMode.range,
              onSelectionChanged: (DateRangePickerSelectionChangedArgs args) {},
            ),

when i select any month calendar changes to dates. Please help how to do this, i've search alot on this, but no luck.

Expected output screenshot

enter image description here


Solution

  • You can use minDate and maxDate params for limiting the range. However, the user can still change view to years mannually by clicking on the year on top. This can be disabled by setting allowViewNavigation to false.

    So in your case the complete code will look like this:

    return SfDateRangePicker(
      minDate: DateTime(2024,1),
      maxDate: DateTime(2024,3,31),
      allowViewNavigation: false,
      view: DateRangePickerView.month,
      selectionMode: DateRangePickerSelectionMode.range,
      onSelectionChanged: (DateRangePickerSelectionChangedArgs args) {},
    )