搜索插件、代码仓与 APP 分类

persian_datetime_picker 封面
插件详情v3.2.0

persian_datetime_picker

一个用于 Flutter 的波斯(法语、沙姆西、贾拉利)日期时间选择器,灵感来自 Material 日期时间选择器。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
6640
喜欢数
299
Pub 分数
150

安装插件

flutter pub add persian_datetime_picker

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,提供受 Material Design 启发的波斯语(法尔西语、沙姆西、贾拉利)日期和时间选择器。它使用户能够选择贾拉利日历系统中的日期和时间,非常适合面向波斯语使用者的应用程序。该选择器支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,确保在各种设备上保持一致的用户体验。它可无缝集成到 Flutter 的 UI 框架中,并提供可自定义的样式和行为。

适合场景

  • 选择伊朗历日期
  • 为伊朗或波斯语使用者构建应用程序
  • 将公历日历集成到表单中
  • 支持多语言日期输入
  • 创建符合文化背景的用户界面

主要特点

  • Jalali(波斯)日历支持
  • Material 风格设计
  • 跨平台兼容性
  • 可自定义外观
  • 与 Flutter 表单轻松集成
  • 时间与日期选择

适合对象

  • 针对伊朗或波斯语地区应用
  • 需要波斯历功能的开发者
  • 需要文化相关日期选择器的项目
  • 具有国际化需求的Flutter应用
  • 需要本地化日期输入的UI组件

使用建议

  • 需要了解伊朗历系统
  • 可能需要额外的本地化支持非波斯文文本
  • 可能存在平台特定的渲染差异
  • 与主流包相比,文档有限
  • 依赖外部 GitHub 仓库以获取更新

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Persian (Farsi, Shamsi, Jalali) Date & Time Picker for Flutter

pub package APK

Persian DateTime Picker Banner

Overview

A Persian Date & Time picker inspired by Material Design's DateTime picker, built on the shamsi_date library. It offers full support for the Persian (Jalali) calendar and is highly customizable, including compatibility with Material 3.

Additionally, it supports multiple languages, including Persian, Dari, Kurdish, Pashto, and custom locales, all while ensuring seamless integration with Flutter and maintaining Material Design standards.

️ Features

  • 🌟 Fully supports Persian (Jalali) calendar
  • 🛠 Highly customizable
  • 💻 Supports Material 3
  • 🌎 Multi-language support: Persian, Dari, Kurdish, Pashto, and custom locales
  • 📱 Compatible with Material Design standards

️ 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';

Add localization to MaterialApp:

    return MaterialApp(
      title: 'Date and Time Pickers',
      locale: const Locale("fa", "IR"),
      supportedLocales: const [
        Locale("fa", "IR"),
        Locale("en", "US"),
      ],
      localizationsDelegates: const [
        // Add Localization
        PersianMaterialLocalizations.delegate,
        PersianCupertinoLocalizations.delegate,
        // DariMaterialLocalizations.delegate, Dari
        // DariCupertinoLocalizations.delegate,
        // PashtoMaterialLocalizations.delegate, Pashto
        // PashtoCupertinoLocalizations.delegate,
        // SoraniMaterialLocalizations.delegate, Kurdish
        // SoraniCupertinoLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      ...
    );

️ Usage Examples

1. Persian Date Picker

Screenshot 1

Jalali? picked = await showPersianDatePicker(
  context: context,
  initialDate: Jalali.now(),
  firstDate: Jalali(1385, 8),
  lastDate: Jalali(1450, 9),
  holidayConfig: PersianHolidayConfig(
    weekendDays: {7}
  ),
  initialEntryMode:
      PersianDatePickerEntryMode.calendarOnly,
  initialDatePickerMode: PersianDatePickerMode.year,
);
var label = picked.formatFullDate();
2. Persian Time Picker

Screenshot 1 Screenshot 2

var picked = await showTimePicker(
  context: context,
  initialTime: TimeOfDay.now(),
  initialEntryMode: TimePickerEntryMode.input,
  builder: (BuildContext context, Widget? child) {
    return Directionality(
      textDirection: TextDirection.rtl,
      child: MediaQuery(
        data: MediaQuery.of(context)
            .copyWith(alwaysUse24HourFormat: true),
        child: child!,
      ),
    );
  },
);
if (picked != null) String label = picked.toString();
3. Modal Bottom Sheet with Persian Cupertino Date Picker

Screenshot 1

Jalali? pickedDate = await showModalBottomSheet<Jalali>(
  context: context,
  builder: (context) {
    Jalali? tempPickedDate;
    return Container(
      height: 250,
      child: Column(
        children: <Widget>[
          Container(
            child: Row(
              mainAxisAlignment:
                  MainAxisAlignment.spaceBetween,
              children: <Widget>[
                CupertinoButton(
                  child: Text(
                    'لغو',
                    style: TextStyle(
                      fontFamily: 'Dana',
                    ),
                  ),
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                ),
                CupertinoButton(
                  child: Text(
                    'تایید',
                    style: TextStyle(
                      fontFamily: 'Dana',
                    ),
                  ),
                  onPressed: () {
                    print(
                        tempPickedDate ?? Jalali.now());
                    Navigator.of(context).pop(
                        tempPickedDate ?? Jalali.now());
                  },
                ),
              ],
            ),
          ),
          Divider(
            height: 0,
            thickness: 1,
          ),
          Expanded(
            child: Container(
              child: PersianCupertinoDatePicker(
                initialDateTime: Jalali.now(),
                mode:
                    PersianCupertinoDatePickerMode.time,
                onDateTimeChanged: (Jalali dateTime) {
                  tempPickedDate = dateTime;
                },
              ),
            ),
          ),
        ],
      ),
    );
  },

if (pickedDate != null) {
   String label = '${pickedDate.toJalaliDateTime()}';
}
4. Persian Date Range Picker

Screenshot 1 Screenshot 2

var picked = await showPersianDateRangePicker(
  context: context,
  initialDateRange: JalaliRange(
    start: Jalali(1400, 1, 2),
    end: Jalali(1400, 1, 10),
  ),
  firstDate: Jalali(1385, 8),
  lastDate: Jalali(1450, 9),
  initialDate: Jalali.now(),
);
String  label =
      "${picked?.start?.toJalaliDateTime() ?? ""} ${picked?.end?.toJalaliDateTime() ?? ""}";
5. Customizing Date Picker Styles

You can customize the styles of the PersianDateTimePicker and PersianCupertinoDatePicker using the DatePickerTheme within your app's ThemeData. Additionally, you can apply specific styles by wrapping the date picker with Theme in the builder.

Example for Persian Date Picker

Add the DatePickerTheme to your ThemeData:

return MaterialApp(
  theme: ThemeData(
    // Other theme properties...
    datePickerTheme: DatePickerTheme(
      backgroundColor: Colors.white, // Background color of the date picker
      primaryColor: Colors.teal, // Primary color for the date picker
      textColor: Colors.black, // Text color
      // Customize more properties as needed
    ),
  ),
  // ...
);
Customizing Persian Date Picker with Theme in Builder

You can also customize the Persian date picker on a per-instance basis by wrapping it with a Theme in the builder:

Jalali? picked = await showPersianDatePicker(
  context: context,
  initialDate: Jalali.now(),
  firstDate: Jalali(1385, 8),
  lastDate: Jalali(1450, 9),
  builder: (context, child) {
    return Theme(
      data: Theme.of(context).copyWith(
        primaryColor: Colors.teal, // Override primary color
        accentColor: Colors.amber, // Override accent color
        // Add more customization here
      ),
      child: child!,
    );
  },
);
Example for Persian Cupertino Date Picker

To customize the PersianCupertinoDatePicker, you can similarly apply a CupertinoTheme:

showCupertinoModalPopup(
  context: context,
  builder: (context) {
    return CupertinoTheme(
      data: CupertinoThemeData(
        textTheme: CupertinoTextThemeData(
          dateTimePickerTextStyle: TextStyle(color: Colors.white),
        ),
        // Add more customization here
      ),
      child: Container(
        height: 300,
        child: PersianCupertinoDatePicker(
          mode: PersianCupertinoDatePickerMode.dateAndTime,
          onDateTimeChanged: (Jalali dateTime) {
            // Handle date change
          },
        ),
      ),
    );
  },
);
Customization Note

All customization options for the PersianDateTimePicker and PersianCupertinoDatePicker are similar to those of the native Flutter date pickers. You can easily apply styles using ThemeData, DatePickerTheme, or by wrapping the pickers with Theme in the builder, just like you would with native Flutter widgets.

6. Using Material 2 Instead of Material 3

If you prefer to use Material 2 instead of Material 3 for your application, you can do so by setting the useMaterial3 parameter to false in the MaterialApp widget. This ensures that the application uses the Material 2 design principles.

Example

Here’s how to set up your MaterialApp to use Material 2:

return MaterialApp(
  title: 'Persian DateTime Picker',
  theme: ThemeData(
    useMaterial3: false, // Set to false to use Material 2
    datePickerTheme: DatePickerTheme(
      backgroundColor: Colors.white,
      primaryColor: Colors.teal,
      textColor: Colors.black,
      // Additional customizations
    ),
  ),
  home: MyHomePage(),
);

️ Support Us

Feel free to check it out and give it a ️ if you love it. Follow me for more updates and projects!

️ Contributions and Feedback

Pull requests and feedback are always welcome!
Feel free to reach out at [mem.amir.m@gmail.com](mailto:mem.amir.m@gmail.com) or connect with me on LinkedIn.

Banner designed by Nader Mozaffari

️ Project License:

This project is licensed under the MIT License.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。