Flutter 波斯日历:用于 Jalali(波斯)日期显示的 Widget

这个 Flutter 包提供了一个简单且可定制的波斯日历 Widget,可以轻松集成到您的 Flutter 项目中。该包基于 shamsi_date。
特点
- 过滤开始和结束日期:您可以添加开始日期和结束日期来过滤显示的日期。
- 自定义选项:通过可自定义的选项,您可以根据应用程序的主题调整日历的外观。
用法
将其添加到您的 pubspec.yaml 文件中
dependencies:
flutter_persian_calendar: ^0.0.2
然后,在终端中运行以下命令
flutter pub get
在您的库中添加以下导入
import 'package:flutter_persian_calendar/flutter_persian_calendar.dart';
查看示例以了解用法
//import package at top of class
import 'package:flutter_persian_calendar/flutter_persian_calendar.dart';
//Create a button to user tap on it and show calendar to select date
ElevatedButton(
onPressed: () {
//Show calendar in Dialog
showDialog(
context: context,
builder: (context) {
return Dialog(
child:
shamsiDateCalendarWidget(context, calendarDarkTheme),
);
},
);
},
child: const Text('Select Date'),
);
//Can create a base Calendar widget to show with different Themes
PersianCalendar shamsiDateCalendarWidget(
BuildContext context,
//Pass different Theme
PersianCalendarTheme calendarTheme,
) {
return PersianCalendar(
calendarHeight: 376, //set height of calendar widget to 376
calendarWidth: 360, //set width of calendar widget to 360
selectedDate: selectedDate, // the selected date shown in initializing calendar widget
onDateChanged: (newDate) {
// type of newDate and selectedDate should be Jalali
selectedDate = newDate; // set the selectedDate to new selected date
},
onConfirmButtonPressed: () {
Navigator.pop(context); // pop widget when user press on confirm button
},
calendarStartDate: Jalali(1300, 4, 12), // show calendar from 1300/4/12
calendarEndDate: Jalali(1402, 7, 10), // show calendar until 1402/7/10
calendarTheme: calendarTheme, // set calendarTheme that is passed here
);
}
自定义
您可以在 PersianCalendarTheme 中更改颜色、文本样式以及项目的宽度和高度。这是一个自定义的浅色主题
// Model of calendar Theme
PersianCalendarTheme(
backgroundColor: const Color(0XFFEDF2F4),
selectedColor: const Color(0XFFEF233C),
headerBackgroundColor: const Color(0XFF8D99AE),
textStyle: const TextStyle(
fontSize: 14,
color: Colors.black,
),
selectedItemTextStyle: const TextStyle(
fontSize: 14,
color: Color(0XFFF2F2F2),
),
confirmButtonTextStyle: const TextStyle(
fontSize: 14,
color: Color(0XFFF2F2F2),
),
headerTextStyle: const TextStyle(
fontSize: 14,
color: Colors.black,
),
);
输出截图

贡献
我们欢迎社区的贡献!如果您想为 Flutter 波斯日历的开发做出贡献,请遵循这些指南
报告问题
如果您在使用该包时遇到任何问题或有改进建议,请在 GitHub 问题跟踪器 上打开一个 issue。报告问题时,请提供问题的详细信息,包括重现步骤以及您的环境(Flutter 版本、平台等)。
进行更改
- Fork该存储库。
- 为您的功能或 bug 修复创建一个新分支:
git checkout -b feature/my-feature或git checkout -b bugfix/fix-issue。 - 进行更改并进行彻底测试。
- 提交您的更改:
git commit -m 'Add some feature'。 - 推送到分支:
git push origin feature/my-feature。 - 提交一个拉取请求。
您可以根据自己的喜好自由使用或修改此版本!