calendar_date_picker2 2.0.1

SDKflutter
Platformandroidioswindowslinuxmacosweb

A lightweight and customizable calendar picker based on Flutter CalendarDatePicker, with support for single date picker, range picker and multi picker.

CalendarDatePicker2

Pub Package Pub Package GitHub Repo stars

A lightweight and customizable calendar picker based on Flutter CalendarDatePicker, with support for single date picker, range picker and multi picker.

single-mode-pickermulti-mode-pickerrange-picker-modedialog-function
single modemulti moderange modedialog function
single-scroll-mode-pickermulti-scroll-mode-pickerrange-scroll-picker-modedialog-scroll-function
single scrollmulti scrollrange scrolldialog scroll

Intro

CalendarDatePicker2 consists of two main widgets:

  • CalendarDatePicker2, this widget only includes the calendar UI and will emit event whenever user taps a different date.
  • CalendarDatePicker2WithActionButtons, this widget includes calendar UI and the action buttons (CANCEL & OK). This widget will only emit the updated value when user taps 'OK' button.

Features

  • Extended CalendarDatePicker allows null initialDate
  • Highly Customizable UI
  • Supports three modes: single, multi and range
  • Supports four views: day, month, year and scroll
  • Built-in showCalendarDatePicker2Dialog
  • Multi-language supports
  • Support of Material 3

Migrate from 0.x.x

Version 1.x.x will by default enable month picker. If you want to migrate to v1.x.x from v0.x.x and would like to keep the old behavior, you will need to set disableMonthPicker to true.

Migrate from 1.x.x

If your flutter SDK is above flutter SDK 3.27.0, you can safely migrate to v2.x.x. Otherwise you should use v1.x.x to avoid dependency issues.

How to use

Make sure to check out examples for more details.

Installation

Add the following line to pubspec.yaml:

dependencies:
calendar_date_picker2: ^2.0.1

Basic setup

The complete example is available here.

CalendarDatePicker2 requires you to provide config and value:

  • config contains the configurations for your calendar setup and UI.
  • value is initial values passed into your calendar picker, value must be a List.

The minimum working sample

CalendarDatePicker2(
  config: CalendarDatePicker2Config(),
  value: _dates,
  onValueChanged: (dates) => _dates = dates,
);

Single Date Picker Configuration

During the initialization of CalendarDatePicker2Config the calendarType of the config instance will by default set to CalendarDatePicker2Type.single, so you don't have to set the calendar type specifically.

Multi Date Picker Configuration

In order to use multi mode date picker, you will need to set the calendarType of config to CalendarDatePicker2Type.multi:

CalendarDatePicker2(
  config: CalendarDatePicker2Config(
      calendarType: CalendarDatePicker2Type.multi,
  ),
  value: _dates,
  onValueChanged: (dates) => _dates = dates,
);

Range Date Picker Configuration

In order to use range mode date picker, you will need to set the calendarType of config to CalendarDatePicker2Type.range:

CalendarDatePicker2(
  config: CalendarDatePicker2Config(
      calendarType: CalendarDatePicker2Type.range,
  ),
  value: _dates,
  onValueChanged: (dates) => _dates = dates,
);

Use built-in dialog display method

This package includes built-in support to display calendar as a dialog. To use it, you will need to call showCalendarDatePicker2Dialog, which takes three required arguments: context, config, dialogSize:

...
var results = await showCalendarDatePicker2Dialog(
  context: context,
  config: CalendarDatePicker2WithActionButtonsConfig(),
  dialogSize: const Size(325, 400),
  value: _dates,
  borderRadius: BorderRadius.circular(15),
);
...

Config options

For CalendarDatePicker2 widget

ArgumentTypeDescription
configCalendarDatePicker2ConfigCalendar UI related configurations
valueList<DateTime?>The selected [DateTime]s that the picker should display.
onValueChangedValueChanged<List<DateTime>>?Called when the selected dates changed
displayedMonthDateDateTime?Date to control calendar displayed month
onDisplayedMonthChangedValueChanged<DateTime>?Called when the user navigates to a new month/year in the picker under non-scroll mode

For CalendarDatePicker2Config:

OptionTypeDescription
calendarTypeCalendarDatePicker2Type?Calendar picker type, has 3 values: single, multi, range
rangeBidirectionalbool?Flag to enable selecting dates range also in reverse-chronological order
firstDateDateTime?The earliest allowable DateTime user can select
lastDateDateTime?The latest allowable DateTime user can select
currentDateDateTime?The DateTime representing today which will be outlined in calendar
calendarViewModeCalendarDatePicker2Mode?The initially displayed view of the calendar picker, with four options available: day, month, year and scroll
calendarViewScrollPhysicsScrollPhysics?The scroll physics for the calendar month view
dynamicCalendarRowsbool?Flag to enable dynamic calendar rows based on specific month
allowSameValueSelectionbool?Flag to control [onValueChanged] behavior
animateToDisplayedMonthDatebool?Flag to always animate to the displayedMonthDate
semanticsDictionaryMap?Custom dictionary for semantics labels
disableVibrationbool?Flag to disable vibration on date selection
weekdayLabelsList<String>?Custom weekday labels, should starts with Sunday
weekdayLabelTextStyleTextStyle?Custom text style for weekday labels
weekdayLabelBuilderWeekdayLabelBuilder?Function to provide full control over weekday label widget
firstDayOfWeekint?Index of the first day of week, where 0 points to Sunday, and 6 points to Saturday.
lastMonthIconWidget?Custom icon for last month button control
hideLastMonthIconbool?Flag to hide last month icon
nextMonthIconWidget?Custom icon for next month button control
hideNextMonthIconbool?Flag to hide next month icon
controlsHeightdouble?Custom height for calendar control toggle's height
controlsTextStyleTextStyle?Custom text style for calendar mode toggle control
centerAlignModePickerbool?Flag to centralize year and month text label in controls
modePickersGapdouble?Custom gap distance between month and year mode pickers
disableModePickerbool?Flag to disable mode picker and hide the toggle icon
modePickerTextHandlerModePickerTextHandler?Function to control mode picker displayed text
modePickerBuilderModePickerBuilder?Function to provide full control over mode picker UI
customModePickerIconWidget?Custom icon for the mode picker button icon
useAbbrLabelForMonthModePickerbool?Use Abbreviation label for month mode picker, only works when month picker is enabled
dayViewControllerPageController?Custom page controller for the calendar day view
dayMaxWidthdouble?Max width of day widget. When [dayMaxWidth] is not null, it will override default size settings
dayBorderRadiusBorderRadius?Custom border radius for day indicator
dayTextStyleTextStyle?Custom text style for calendar day(s)
todayTextStyleTextStyle?Custom text style for current calendar day(s)
disabledDayTextStyleTextStyle?Custom text style for disabled calendar day(s)
dayTextStylePredicateDayTextStylePredicate?Function to provide full control over calendar day(s) text style
selectedDayHighlightColorColor?The highlight color selected day
selectedDayTextStyleTextStyle?Custom text style for selected calendar day(s)
selectableDayPredicateSelectableDayPredicate?Function to provide full control over which dates in the calendar can be selected
selectedRangeDayTextStyleTextStyle?Custom text style for selected range calendar day(s)
selectedRangeHighlightColorColor?The highlight color for day(s) included in the selected range
selectedRangeDecorationPredicateSelectedRangeDecorationPredicate?Predicate to determine the day widget box decoration for a day in selected range
selectedRangeHighlightBuilderSelectedRangeHighlightBuilder?Function to provide full control over range picker highlight
daySplashColorColor?The splash color of the day widget
dayBuilderDayBuilder?Function to provide full control over day widget UI
dayModeScrollDirectionAxis?Axis scroll direction for [CalendarDatePicker2Mode.day] mode
monthViewControllerScrollController?Custom scroll controller for the calendar month view
monthBuilderMonthBuilder?Function to provide full control over month widget UI
hideMonthPickerDividersbool?Flag to hide dividers on month picker
selectableMonthPredicateSelectableMonthPredicate?Function to provide full control over which month in the month list can be selected.
disableMonthPickerbool?Flag to disable month picker
monthTextStyleTextStyle?Custom text style for month(s)
selectedMonthTextStyleTextStyle?Custom text style for selected month(s)
disabledMonthTextStyleTextStyle?Custom text style for disabled month(s)
yearViewControllerScrollController?Custom scroll controller for the calendar year view
yearBorderRadiusBorderRadius?Custom border radius for year indicator
yearTextStyleTextStyle?Custom text style for year(s)
selectedYearTextStyleTextStyle?Custom text style for selected year(s)
disabledYearTextStyleTextStyle?Custom text style for disabled year(s)
selectableYearPredicateSelectableYearPredicate?Function to provide full control over which year in the year list be selected.
yearBuilderYearBuilder?Function to provide full control over year widget UI
hideYearPickerDividersbool?Flag to hide dividers on year picker
scrollViewTopHeaderTextStyleTextStyle?Custom text style for scroll view top week labels header
hideScrollViewTopHeaderbool?Flag to hide top week labels header on scroll view picker
hideScrollViewTopHeaderDividerbool?Flag to hide top week labels header divider on scroll view
hideScrollViewMonthWeekHeaderbool?Flag to hide month calendar week labels header on scroll view
scrollViewConstraintsBoxConstraints?BoxConstraints for the scroll calendar view, only work for scroll mode
scrollViewMonthYearBuilderScrollViewMonthYearBuilder?Function to provide full control over scroll calendar month year UI
scrollViewOnScrollingScrollViewOnScrolling?Function to callback over scrolling on scroll view
scrollViewControllerScrollController?Custom scroll controller to the scroll calendar view

In addition to the configurations above, CalendarDatePicker2WithActionButtonsConfig has 9 extra options

OptionTypeDescription
gapBetweenCalendarAndButtonsdouble?The gap between calendar and action buttons
cancelButtonTextStyleTextStyle?Text style for cancel button
cancelButtonWidget?Custom cancel button
okButtonTextStyleTextStyle?Text style for ok button
okButtonWidget?Custom ok button
openedFromDialogbool?Is the calendar opened from dialog
closeDialogOnCancelTappedbool?Close dialog after user taps the CANCEL button
closeDialogOnOkTappedbool?Close dialog after user taps the OK button
buttonPaddingEdgeInsets?Custom wrapping padding for Ok & Cancel buttons

Custom UI

By using the configs above, you could make your own custom calendar picker as your need.

imageimageimage

CalendarDatePicker2WithActionButtons(
  config: CalendarDatePicker2WithActionButtonsConfig(
    firstDayOfWeek: 1,
    calendarType: CalendarDatePicker2Type.range,
    selectedDayTextStyle: TextStyle(color: Colors.white, fontWeight: FontWeight.w700),
    selectedDayHighlightColor: Colors.purple[800],
    centerAlignModePicker: true,
    customModePickerIcon: SizedBox(),
    dayBuilder: _yourDayBuilder,
    yearBuilder: _yourYearBuilder,
  ),
  value: _dates,
  onValueChanged: (dates) => _dates = dates,
);

Multi-language support

This package has multi-language supports. To enable it, add your Locale into the wrapping MaterialApp:

MaterialApp(
  localizationsDelegates: GlobalMaterialLocalizations.delegates,
  supportedLocales: const [
    Locale('en', ''),
    Locale('zh', ''),
    Locale('ru', ''),
    Locale('es', ''),
    Locale('hi', ''),
  ],
  ...
);
imageimageimageimage
中文русскийespañolहिंदी

Contributions

Feel free to contribute to this project. 🍺 Pull requests are welcome!

There are some tips before creating a PR:

  • Please always create an issue/feature before raising a PR
  • Please always create a minimum reproducible example for an issue
  • Please use the official Dart Extension as your formatter or use dart format . -l 80 if you are not using VS Code
  • Please keep your changes to its minimum needed scope (avoid introducing unrelated changes)
  • Please follow this git commit convention by adding feat: or fix: to your PR commit