dhiyaaulauliyaa / scroll_datetime_picker

MIT License
5 stars 9 forks source link

Scroll DateTime Picker

codecov pub package License: MIT

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.

🔬 Test The Package 🔬

Key Features

Usage

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;
  }),
),

Features Details

🗓️ Customize Date/Time Format

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:


📅 Customize Date/Time Order

Arrange 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:


🌍 Customize Date/Time Locale

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:


✏️ Customize Date/Time TextStyles

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:

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,
  ),
),

🛞 Customize Scroll Wheel Appearance

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(),
);

📜 Choose Between Infinite/Finite Scroll

Opt for either finite or infinite scrolling, depending on your needs.

Choose between finite and infinite scrolling based on your requirements:


🎨 Fully Customize Date/Time Picker Appearance

Gain complete control over the date/time picker's appearance with a variety of customization options:

Customize Flex Width for Every Date/Time Item

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.

Customize the Center Area of the Picker

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.

Customize Each Item Based on Its State

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.

Customize Using BoxDecoration

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:

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


🧠 Smart Detection on Invalid Date and Leap Year Handling

Ensure a smooth experience with intelligent handling of invalid dates and leap years.

😇 Contribute

We are always thrilled to welcome anyone who wishes to enhance this package. Your contributions are greatly appreciated! 🙇‍♂️

💡 Issue / Feature Requests

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. 🙏