Welcome to the Scroll DateTime Picker – a versatile and highly customizable Flutter package that allows you to effortlessly pick dates, times, or both. Inspired by the CupertinoDatePicker, our package provides a wealth of features for your date and time selection needs.
Customizer Page
by clicking the Customize Here
button.Add to pubspec.yaml
dart pub add scroll_datetime_picker
Import the package
import 'package:scroll_datetime_picker/scroll_datetime_picker.dart';
Simple usage example
ScrollDateTimePicker(
itemExtent: 54,
infiniteScroll: true,
dateOption: DateTimePickerOption(
dateFormat: DateFormat('yyyyMMMdd'),
minDate: DateTime(2000, 6),
maxDate: DateTime(2024, 6),
initialDate: time,
),
onChange: (datetime) => setState(() {
time = datetime;
}),
),
Tailor the date and time format to your specific requirements.
Easily modify the date and time format by adjusting the dateFormat
property in DateTimePickerOption
.
dateOption: DateTimePickerOption(
dateFormat: DateFormat('EddMMMy'),
),
The pattern accepted is based on the intl package. See the DateFormat docs to find more about the pattern. DateFormat example patterns:
EEEE, dd MMM yyyy
→ Monday, 01 Jan 2000hh:mm:ss a
→ 06:30:00 pmDateFormat.yMMMd()
→ 2020 Jan 01DateFormat.jms()
→ 18:30:00Arrange date and time elements in your preferred order.
To customize Date/Time order to show on the picker, simply modify the pattern that is passed to the dateFormat
param on DateTimePickerOption
.
Example:
dateOption: DateTimePickerOption(
dateFormat: DateFormat('yMMMMdd'),
),
dateOption: DateTimePickerOption(
dateFormat: DateFormat('ddMMMMy'),
),
Set the locale for date and time, ensuring localization accuracy.
Tailor the date and time locale displayed in the picker by passing the locale to the dateFormat
parameter in DateTimePickerOption
. If no locale is specified, the package will use the default locale. Locale options are based on the intl package. See the Locale docs to find more about the locale. Here's how to use it:
dateOption: DateTimePickerOption(
dateFormat: DateFormat('yMMMMdd', 'en'),
),
dateOption: DateTimePickerOption(
dateFormat: DateFormat('yMMMMdd', 'fr'),
),
dateOption: DateTimePickerOption(
dateFormat: DateFormat('ddMMMMy'),
),
Craft your own text styles for a personalized appearance.
Personalize the appearance of the date and time text using the DateTimePickerStyle
class. Adjust the TextStyle
properties for:
ActiveStyle
: Style for text in the center area of the pickerInactiveStyle
: Style for text outside the center area.DisabledStyle
: Style for invalid date/time text. Invalid date will be explained in Invalid Date sectionHere's an example:
style: DateTimePickerStyle(
activeStyle: TextStyle(
fontSize: 24,
letterSpacing: -0.5,
color: Theme.of(context).primaryColor,
),
inactiveStyle: TextStyle(
fontSize: 20,
color: Theme.of(context).primaryColor.withOpacity(0.7),
),
disabledStyle: TextStyle(
fontSize: 20,
color: Theme.of(context).disabledColor,
),
),
Define the wheel's appearance, from flat to rounded.
Set custom appearance for the picker wheel. The parameters here are based on flutter's ListWheelScrollView. You can make the picker looks flat or rounded like a wheel. Usage example:
wheelOption = const DateTimePickerWheelOption(
perspective: 0.01,
diameterRatio: 1.5,
squeeze: 1.1,
offAxisFraction: 1.5,
physics: BouncingScrollPhysics(),
);
Opt for either finite or infinite scrolling, depending on your needs.
Choose between finite and infinite scrolling based on your requirements:
ScrollDateTimePicker(
itemExtent: 54,
infiniteScroll: false // Finite scroll
onChange: (_){}
dateOption: DateTimePickerOption(
dateFormat: DateFormat('EddMMMy'),
minDate: DateTime(2000, 6),
maxDate: DateTime(2024, 6),
),
),
ScrollDateTimePicker(
itemExtent: 54,
infiniteScroll: true // Infinite scroll
onChange: (_){}
dateOption: DateTimePickerOption(
dateFormat: DateFormat('EddMMMy'),
minDate: DateTime(2000, 6),
maxDate: DateTime(2024, 6),
),
),
Gain complete control over the date/time picker's appearance with a variety of customization options:
You can control the width (flex) of each date/time item using the DateTimePickerItemFlex
class:
ScrollDateTimePicker(
itemFlex: const DateTimePickerItemFlex(
weekdayFlex: 7,
dayFlex: 2,
monthFlex: 8,
yearFlex: 4,
),
),
In this example, the flex values for each item type (weekday, day, month, year) are specified.
You can customize the center area of the picker (usually the area that indicates the date/time chosen) using the DateTimePickerCenterWidget
class. Users can choose to customize the center area for all items at once or individually for each date/time item:
ScrollDateTimePicker(
centerWidget: DateTimePickerCenterWidget(
builder: (context, constraints, child) => const DecoratedBox(
decoration: ShapeDecoration(
shape: StadiumBorder(side: BorderSide(width: 3)),
color: AppColor.secondary,
),
),
),
),
In this example, the center area is customized with a specific shape decoration and color.
You can customize each item on the date picker based on its state (active at the center area, non-active outside the center area, disabled if the item is invalid) using the itemBuilder
parameter:
ScrollDateTimePicker(
itemBuilder: (context, pattern, text, isActive, isDisabled) =>
Text(
text,
style: TextStyle(
color: isDisabled
? Colors.grey
: isActive
? Colors.blue
: Colors.black,
),
),
),
In this example, the text style is customized based on whether the item is active or disabled.
You can customize the visual aspects such as color, border, and border radius of the date/time picker using the DateTimePickerStyle
class. Modify the BoxDecoration
parameters to achieve your desired appearance:
ActiveDecoration
: Style for the widget in the center area of the picker.InactiveDecoration
: Style for the widget outside the center area of the picker.CenterDecoration
: Style that will be applied to the center area of the picker.Here's an example:
style: DateTimePickerStyle(
activeStyle: TextStyle(
fontSize: 24,
letterSpacing: -0.5,
color: Theme.of(context).primaryColor,
),
inactiveStyle: TextStyle(
fontSize: 20,
color: Theme.of(context).primaryColor.withOpacity(0.7),
),
disabledStyle: TextStyle(
fontSize: 20,
color: Theme.of(context).disabledColor,
),
),
In this example, the active, inactive, and disabled item of the picker is customized with a specific TextStyle
Ensure a smooth experience with intelligent handling of invalid dates and leap years.
31 Jun 2021
), the picker will automatically adjust the date. In this case, the day will automatically scrolled to be 30 Jun 2021
30 Feb 2020
, the picker will automatically fix the invalid value. In this case, the day will automatically scrolled to be 29 Feb 2020
We are always thrilled to welcome anyone who wishes to enhance this package. Your contributions are greatly appreciated! 🙇♂️
If you have specific features in mind, don't hesitate to let me know. Please open an issue to discuss your feature requests, and I'll be more than happy to consider them and collaborate towards making this package even better. 🙏