Skip to content

M-amir-M/persian-datetime-picker

Repository files navigation

📆 Persian (Farsi, Shamsi) DateTime Picker for Flutter

A Persian DateTime picker inspired by Material Design's DateTime picker and built upon the shamsi_date library.

pub package APK

Persian DateTime Picker Banner

Features

  • 🌟 Fully supports Persian (Jalali) calendar
  • 🛠 Built using the stable and widely used shamsi_date library
  • 📱 Compatible with Material Design standards
  • 🧑‍💻 Simple integration with Flutter

Getting Started

To use the Persian DateTime Picker, add the package to your pubspec.yaml:

dependencies:
  persian_datetime_picker: <latest_version>

Then, import it in your Dart code:

import 'package:persian_datetime_picker/persian_datetime_picker.dart';

Usage Examples

1. Persian Date Picker

Jalali picked = await showPersianDatePicker(
  context: context,
  initialDate: Jalali.now(),
  firstDate: Jalali(1385, 8),
  lastDate: Jalali(1450, 9),
);
var label = picked.formatFullDate();

2. Persian Time Picker

var picked = await showTimePicker(
  context: context,
  initialTime: TimeOfDay.now(),
);
var label = picked.persianFormat(context);

3. Modal Bottom Sheet with Persian Date Picker

Jalali pickedDate = await showModalBottomSheet<Jalali>(
  context: context,
  builder: (context) {
    Jalali tempPickedDate;
    return Container(
      height: 250,
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              CupertinoButton(
                child: Text('لغو', style: TextStyle(fontFamily: 'Dana')),
                onPressed: () => Navigator.of(context).pop(),
              ),
              CupertinoButton(
                child: Text('تایید', style: TextStyle(fontFamily: 'Dana')),
                onPressed: () => Navigator.of(context).pop(tempPickedDate ?? Jalali.now()),
              ),
            ],
          ),
          Divider(height: 0, thickness: 1),
          Expanded(
            child: CupertinoTheme(
              data: CupertinoThemeData(
                textTheme: CupertinoTextThemeData(dateTimePickerTextStyle: TextStyle(fontFamily: "Dana")),
              ),
              child: PCupertinoDatePicker(
                mode: PCupertinoDatePickerMode.dateAndTime,
                onDateTimeChanged: (Jalali dateTime) {
                  tempPickedDate = dateTime;
                },
              ),
            ),
          ),
        ],
      ),
    );
  },
);

4. Persian Date Range Picker

var picked = await showPersianDateRangePicker(
  context: context,
  initialEntryMode: PDatePickerEntryMode.input,
  initialDateRange: JalaliRange(
    start: Jalali(1400, 1, 2),
    end: Jalali(1400, 1, 10),
  ),
  firstDate: Jalali(1385, 8),
  lastDate: Jalali(1450, 9),
);

Contributions and Feedback

Pull requests and feedback are always welcome!
Feel free to reach out at [email protected] or connect with me on LinkedIn.

Banner designed by Nader Mozaffari