CalendarDatePicker2 - A lightweight and customizable calendar picker based on Flutter CalendarDatePicker

Overview

CalendarDatePicker2

Pub Package Pub Package

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

single-mode-picker multi-mode-picker range-picker-mode dialog-function
single mode multi mode range mode dialog function

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
  • Customizable UI
  • Supports three modes: single, multi and range
  • Built-in showCalendarDatePicker2Dialog

How to use

Make sure to check out examples for more details.

Installation

Add the following line to pubspec.yaml:

dependencies:
  calendar_date_picker2: ^0.1.7

Basic setup

The complete example is available here.

TableCalendar requires you to provide config and initialValue:

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

The minimum working sample

CalendarDatePicker2(
  config: CalendarDatePicker2Config(),
  initialValue: [],
);

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,
  ),
  initialValue: [],
);

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,
  ),
  initialValue: [],
);

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: CalendarDatePicker2Config(),
  dialogSize: const Size(325, 400),
  initialValue: _dialogCalendarPickerValue,
  borderRadius: 15,
);
...

Config options

For CalendarDatePicker2Config:

Option Type Description
calendarType CalendarDatePicker2Type? Calendar picker type, has 3 values: single, multi, range
firstDate DateTime? The earliest allowable DateTime user can select
lastDate DateTime? The latest allowable DateTime user can select
currentDate DateTime? The DateTime representing today which will be outlined in calendar
calendarViewMode DatePickerMode? The initially displayed view of the calendar picker
weekdayLabels List? Custom weekday labels, should starts with Sunday
weekdayLabelTextStyle TextStyle? Custom text style for weekday labels
controlsHeight double? Custom height for calendar control toggle's height
lastMonthIcon Widget? Custom icon for last month button control
nextMonthIcon Widget? Custom icon for next month button control
controlsTextStyle TextStyle? Custom text style for calendar mode toggle control
dayTextStyle TextStyle? Custom text style for calendar day text
selectedDayTextStyle TextStyle? Custom text style for selected calendar day text
selectedDayHighlightColor Color? The highlight color selected day

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

Option Type Description
gapBetweenCalendarAndButtons double? The gap between calendar and action buttons
cancelButtonTextStyle TextStyle? Text style for cancel button
cancelButton Widget? Custom cancel button
okButtonTextStyle TextStyle? Text style for ok button
okButton Widget? Custom ok button
openedFromDialog bool? Is the calendar opened from dialog
shouldCloseDialogAfterCancelTapped bool? If the dialog should be closed when user taps the cancel button

Custom UI

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

CalendarDatePicker2WithActionButtons(
  config: CalendarDatePicker2WithActionButtonsConfig(
    calendarType: CalendarDatePicker2Type.range,
    selectedDayHighlightColor: Colors.purple[800],
  ),
  initialValue: [],
  onValueChanged: (values) => setState(() => _yourVariable = values),
);
Comments
  • [Feature] Calendar starts on Monday

    [Feature] Calendar starts on Monday

    Thank you for your hard work, the calendar is really simple to config and works smooth.

    Is your feature request related to a problem? Please describe. Most european calendars starting on monday. I've seen no api for this feature so it's propably missing.

    Describe the feature you'd like A option to define monday as first day of week would be very nice.

    Bildschirm­foto 2022-11-08 um 15 56 29

    opened by tonbert 3
  • [Feature] Limit Date Range in days

    [Feature] Limit Date Range in days

    Is your feature request related to a problem? Please describe. At the moment the selectable date range is unlimited.

    Describe the feature you'd like An API with limitRangeInDays or similar would be nice to limit the user in max selectable days. When user is clicking a Start-Date, the days outside the limit would get slighty more gray or a custom color and they cant be selected.

    Use cases We have an statistics service which provides only data für 31 days. More days will result in heavy server load. This feature could give the user a direct feedback instead of an error message.

    opened by tonbert 2
  • SliverGeometry is not valid: The

    SliverGeometry is not valid: The "scrollExtent" is negative.

    Hi! I'm trying to use calendar_date_picker2 for my web application and got the errors:

    SliverGeometry is not valid: The "scrollExtent" is negative.
    The RenderSliver that returned the offending geometry was: _RenderSliverFractionalPadding#c2f34 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
      creator: _SliverFractionalPadding ← SliverFillViewport ← Viewport ← IgnorePointer-[GlobalKey#17ad9] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#62556] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#119b9] ← NotificationListener<ScrollMetricsNotification> ← ⋯
      parentData: paintOffset=Offset(0.0, 0.0) (can use size)
      constraints: SliverConstraints(AxisDirection.right, GrowthDirection.forward, ScrollDirection.idle, scrollOffset: 333.3, remainingPaintExtent: 333.3, crossAxisExtent: 294.0, crossAxisDirection: AxisDirection.down, viewportMainAxisExtent: 333.3, remainingCacheExtent: 333.3, cacheOrigin: -0.0)
      geometry: SliverGeometry(scrollExtent: -7000.0, hidden, maxPaintExtent: -7000.0)
    SliverGeometry is not valid: The "scrollExtent" is negative.
    

    My code is the following:

    final dateList = await showCalendarDatePicker2Dialog(
          context: context,
          config: CalendarDatePicker2WithActionButtonsConfig(
            calendarType: CalendarDatePicker2Type.range,
            firstDate: firstDate,
            lastDate: lastDate,
            currentDate: today,
            shouldCloseDialogAfterCancelTapped: true,
            weekdayLabelTextStyle: AppFonts.commonText,
            selectedDayHighlightColor: AppColors.green_0,
            selectedDayTextStyle: AppFonts.commonText,
            dayTextStyle: AppFonts.commonText,
          ),
          dialogSize: Size(
            500.w,
            500.h,
          ),
        );
    

    and it shows empty dialog window: Снимок экрана 2022-08-16 в 12 09 56

    what I did wrong?

    Thanks!

    opened by kharitonovAL 2
  • [Bug] Error occurs when moving the focus with the keyboard

    [Bug] Error occurs when moving the focus with the keyboard

    Thank you for your wonderful library!

    Describe the bug Error occurs when moving the focus with the keyboard. It is reproduced by pressing the left/right key after moving the focus to the calendar section with the Tab key.

    Error log
    
    ════════ Exception caught by services library ══════════════════════════════════
    The following assertion was thrown while processing the key message handler:
    'package:calendar_date_picker2/src/widgets/calendar_date_picker2.dart': Failed assertion: line 680 pos 12: '_focusedDay != null': is not true.
    
    When the exception was thrown, this was the stack
    #2      _MonthPickerState._handleDirectionFocus
    #3      CallbackAction.invoke
    #4      ActionDispatcher.invokeAction
    #5      ShortcutManager.handleKeypress
    #6      _ShortcutsState._handleOnKey
    #7      FocusManager._handleKeyMessage
    #8      KeyEventManager._dispatchKeyMessage
    #9      KeyEventManager.handleRawKeyMessage
    #10     BasicMessageChannel.setMessageHandler.<anonymous closure>
    #11     BasicMessageChannel.setMessageHandler.<anonymous closure>
    #12     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure>
    #13     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure>
    #14     _invoke2.<anonymous closure> (dart:ui/hooks.dart:190:15)
    #18     _invoke2 (dart:ui/hooks.dart:189:10)
    #19     _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42:5)
    #20     _Channel.push (dart:ui/channel_buffers.dart:132:31)
    #21     ChannelBuffers.push (dart:ui/channel_buffers.dart:329:17)
    #22     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:589:22)
    #23     _dispatchPlatformMessage (dart:ui/hooks.dart:89:31)
    (elided 5 frames from class _AssertionError and dart:async)
    KeyMessage: KeyMessage([KeyDownEvent#fc994(physicalKey: PhysicalKeyboardKey#7004f(usbHidUsage: "0x0007004f", debugName: "Arrow Right"), logicalKey: LogicalKeyboardKey#00303(keyId: "0x100000303", keyLabel: "Arrow Right", debugName: "Arrow Right"), character: "UIKeyInputRightArrow", timeStamp: 64:51:42.543241)])
    ════════════════════════════════════════════════════════════════════════════════
    
    ════════ Exception caught by services library ══════════════════════════════════
    'package:calendar_date_picker2/src/widgets/calendar_date_picker2.dart': Failed assertion: line 680 pos 12: '_focusedDay != null': is not true.
    ════════════════════════════════════════════════════════════════════════════════
    
    

    Platforms (please complete the following information):

    • Platforms: [iOS, Mac]

    Minimum Reproduceable Repo

    Code sample
    import 'package:calendar_date_picker2/calendar_date_picker2.dart';
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      final _selected = ValueNotifier('pick!');
      MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: Center(
                child: ValueListenableBuilder<String>(
                    valueListenable: _selected,
                    builder: (_, selected, __) {
                      return Text(selected);
                    })),
            floatingActionButton: Builder(builder: (context) {
              return FloatingActionButton(
                child: const Icon(Icons.calendar_today),
                onPressed: () async {
                  final results = await showCalendarDatePicker2Dialog(
                    context: context,
                    config: CalendarDatePicker2WithActionButtonsConfig(
                      calendarType: CalendarDatePicker2Type.range,
                      shouldCloseDialogAfterCancelTapped: true,
                    ),
                    dialogSize: const Size(325, 400),
                    borderRadius: 15,
                  );
                  if (results != null) {
                    _selected.value = results.toString();
                  }
                },
              );
            }),
          ),
        );
      }
    }
    
    
    opened by zuvola 2
  • [Bug] package ignores app locale, and only shows the english one.

    [Bug] package ignores app locale, and only shows the english one.

    Describe the bug It seems that the package ignore the apps locale when displaying the datepicker and shows it in english.

    To Reproduce Steps to reproduce the behavior:

    1. Set other than english locale for the app.
    2. Implement CalendarDatePicker2Dialog
    var results = await showCalendarDatePicker2Dialog(
                                  context: context,
                                  config: CalendarDatePicker2WithActionButtonsConfig(
                                    calendarType: CalendarDatePicker2Type.range,
                                    selectedDayHighlightColor:
                                        Color(AppColors.yellow),
                                    okButton: Text('Выбрать'),
                                    cancelButton: Text('Отмена'),
                                  ),
                                  dialogSize: Size(
                                      MediaQuery.of(context).size.width * 0.9, 400),
                                  initialValue: [],
                                  borderRadius: 10,
                                );
    
    1. Call the function and open date picker

    Expected behavior Open the date picker and see that the days, months and weeks format is shown in the language of the apps locale.

    Actual Behaviour The datepicker shows everything in english.

    I can see inside the CalendarDatePicker2 widget that you use MaterialLocalizations _localizations, however, it ignores the app's locale.

    I even called print(MaterialLocalizations.of(context).narrowWeekdays); in the same widget I call the date picker and the print result is as expected - it shows the days in the language of the app, but the date picker is still in english.

    Screenshots simulator_screenshot_C005E4D6-51F3-44F2-A3AF-A3BEE2723DDC

    Platforms (please complete the following information):

    • Platforms: both IOS and Android
    opened by appregion 2
  • [Feature] How to get selection date click on ok without closing dialog.

    [Feature] How to get selection date click on ok without closing dialog.

    var results = await showCalendarDatePicker2Dialog( context: context, config: CalendarDatePicker2WithActionButtonsConfig( calendarType: CalendarDatePicker2Type.range, lastDate: DateTime.now(), shouldCloseDialogAfterCancelTapped: true, okButton: InkWell( onTap: () { print('Get Selection Date=====>>>'); }, child: Text('OK'), dialogSize: Size(400, 400), borderRadius: BorderRadius.circular(15), );

    this is my code.
    
    Please, anyone let me know if any idea. 
    Thank you in advance.
    
    enhancement 
    opened by DipakSkywave 1
  • Support dark theme out of the box

    Support dark theme out of the box

    This package seems promising, it would be great if we added default dark mode color scheme and make the current default theme as light mode.

    Also the capability of changing the background color of the dialog should be added.

    opened by awazgyawali 1
  • Added new parameter selectedYearTextStyle

    Added new parameter selectedYearTextStyle

    Enhancement for selectedYearTextStyle.

    Reason: Previously it was not possible to change the text style of the selected year, so it looked inconsistent if using a custom selectedDayTextStyle.

    Added new parameter selectedYearTextStyle and implemented it into calendar_date_picker2.dart, updated Readme.md

    opened by Diaglyonok 0
Releases(Lastest)
Owner
Neo Liu
Work Hard, Play Hard.
Neo Liu
Highly customizable, feature-packed calendar works like google calendar but with more features.

Beca [In Progress] Beca is a Calendar that you could manage your daily tasks and schedule meetings with your friends just like google calendar Concept

Mohammad Javad Hossieni 19 Nov 15, 2022
A Flutter package allows you to easily implement all calendar UI and calendar event functionality. 👌🔝🎉

calendar_view A Flutter package allows you to easily implement all calendar UI and calendar event functionality. For web demo visit Calendar View Exam

Simform Solutions 219 Dec 22, 2022
Flutter calendar app. register schedule and manage in calendar ui.

flutter calendar app. register schedule and manage in calendar ui. save schedule data in firestore. and create widget and read schedule from firestore in widget.

akiho 11 Oct 30, 2022
Flutter Date Picker Library that provides a calendar as a horizontal timeline.

DatePickerTimeline Flutter Date Picker Library that provides a calendar as a horizontal timeline. How To Use Import the following package in your dart

LiLi 0 Oct 25, 2021
Flutter Date Picker Library that provides a calendar as a horizontal timeline

Flutter Date Picker Library that provides a calendar as a horizontal timeline.

Vivek Kaushik 214 Jan 7, 2023
Highly customizable, feature-packed calendar widget for Flutter

Table Calendar Highly customizable, feature-packed Flutter Calendar with gestures, animations and multiple formats. Table Calendar with custom styles

Aleksander Woźniak 1.5k Jan 7, 2023
Datetime picker formfield - A Flutter widget that wraps a TextFormField and integrates the date and/or time picker dialogs.

DateTimeField A TextFormField that emits DateTimes and helps show Material, Cupertino, and other style picker dialogs. Example See the example tab (ex

Jacob Phillips 182 Dec 1, 2022
A persian (farsi,shamsi) datetime picker for flutter, inspired by material datetime picker.

?? A persian (farsi,shamsi) datetime picker for flutter, inspired by material datetime picker. Persian datetime picker inspired by material datetime p

Persian Flutter Community 142 Dec 19, 2022
A Heatmap Calendar based on Github's contributions chart

Flutter Heat Map Calendar A Heat Map Calendar based on Github's contributions chart which can be used to visualize values over time Installing 1. Depe

Pedro H. F. Feitosa 49 Dec 6, 2022
A Flutter package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) dates.

A Flutter package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) dates.

Amirreza Madani 63 Dec 21, 2022
Easy to use and beautiful calendar strip component for Flutter.

Flutter Calendar Strip Easy to use and beautiful calendar strip component for Flutter. Awesome celender widget If this project has helped you out, ple

Siddharth V 176 Dec 14, 2022
Fluboard - Calendar wall-board-display built with Flutter and ❤️

Fluboard Calendar wall-board-display built with Flutter and ❤️ Goals Build calendar board (DAKBoard alternative) which easy to install and easy to cus

iTeqno 10 Dec 27, 2022
Calendar widget for flutter

Calendar Shows a scrolling calendar list of events. This is still relatively basic, it always assumes that the getEvents returns the entire list of ca

null 223 Dec 19, 2022
Calendar widget library for Flutter apps.

Calendarro Calendar widget library for Flutter apps. Offers multiple ways to customize the widget. Getting Started Installation Add dependency to your

Adam Styrc 97 Nov 30, 2022
Flutter Inline Calendar

inline_calendar An inline calendar flutter package inspired by outlook app. It also supports Jalali/Shamsi calendar. Uses theme and locale of context

omid habibi 3 Oct 21, 2022
A calendar widget for Flutter.

flutter_calendar A calendar widget for Flutter Apps. Borrowed DateTime utility functions from the Tzolkin Calendar web element. Usage Add to your pubs

AppTree Software, Inc 336 Sep 6, 2022
Flutter calendar week UI package

Flutter calendar week Flutter calendar week UI package IOS | Android: import 'package:flutter_calendar_week/flutter_calendar_week.dart'; CalendarWeek(

null 67 Dec 12, 2022
A seasonal foods calendar app written in Dart using Flutter.

This project is not actively maintained anymore. However, everybody who wants to do so is more than welcome to work on this project! Thank you for you

Andreas Boltres 63 Nov 19, 2022
Collection of customisable calendar related widgets for Flutter.

calendar_views Collection of customisable calendar related widgets for Flutter. Day View Day View Documentation Set of widgets for displaying a day vi

Zen Lednik 99 Sep 8, 2022