A persian ( farsi ) datepicker for flutter.
A simple example with a TextField which turns into a datepicker
main.dart
import 'package:flutter/material.dart';
import 'package:persian_datepicker/persian_datepicker.dart';
void main() {
runApp(Home());
}
class Home extends StatefulWidget {
@override
HomeState createState() {
return new HomeState();
}
}
class HomeState extends State<Home> {
// our text controller
final TextEditingController textEditingController = TextEditingController();
PersianDatePickerWidget persianDatePicker;
@override
void initState() {
/*Simple DatePicker*/
persianDatePicker = PersianDatePicker(
controller: textEditingController,
// datetime: '1397/06/09',
).initialize();
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('تقویم ساده'),),
body: Builder(builder: (BuildContext context) {
return Container(
child: TextField(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode()); // to prevent opening default keyboard
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return persianDatePicker;
});
},
controller: textEditingController,
),
);
}),
),
);
}
}
Simple DatePicker
Range DatePicker
/*Range DatePicker*/
persianDatePicker = PersianDatePicker(
controller: textEditingController,
rangeDatePicker: true,
// datetime: '1397/06/09',
// finishDatetime: '1397/06/15',
).initialize();
Inline DatePicker
/*Inline DatePicker*/
persianDatePicker = PersianDatePicker(
controller: textEditingController,
datetime: '1397/06/19',
).initialize();
....
return Column(
children: <Widget>[
// Simple Date Picker
Container(
child: persianDatePicker, // just pass `persianDatePicker` variable as child with no ( )
),
TextField(
controller: textEditingController,
),
],
);
Customized DatePicker
You can customize datepicker as you wish, there are a lot of options to set, below code is just a few of them.
/*Customized DatePicker*/
persianDatePicker = PersianDatePicker(
controller: textEditingController,
outputFormat: 'YYYY/MM/DD',
datetime: '1397/08/13',
finishDatetime: '1397/08/17',
daysBorderWidth: 3,
weekCaptionsBackgroundColor: Colors.red,
headerBackgroundColor: Colors.blue.withOpacity(0.5),
headerTextStyle: TextStyle(color: Colors.blue, fontSize: 17),
headerTodayText: Text('امروز', style: TextStyle(fontSize: 15),),
headerTodayIcon: Icon(Icons.access_alarm, size: 15,),
datePickerHeight: 280
).initialize();
The controller of the input which you want to connect it to datepicker. This parameter is required
کنترلر تکست فیلدی که میخواهید به دیت پیکر تبدیل کنید
TextEditingController controller @required
Persian input datetime
ورودی دیت پیکر به فرمت تاریخ پارسی
String datetime Default: today date
Persian input finish datetime, if this option is set, then datepicker changes to range datepicker
ورودی دیت پیکر برای تاریخ پایان به فرمت پارسی، اگر این ورودی ست شود، دیت پیکر به صورت محدوده ای خواهد بود
String finishDatetime
Gregorian input datetime
ورودی دیت پیکر به فرمت تاریخ میلادی
String gregorianDatetime
Gregorian finish datetime, if this option is set, then datepicker changes to range datepicker
ورودی دیت پیکر برای تاریخ پایان به فرمت گرگورین، اگر این ورودی ست شود، دیت پیکر به صورت محدوده ای خواهد بود
String gregorianFinishDatetime
Output format of the datepicker ( display format ) فرمت خروجی نمایش تاریخ
String outputFormat Default: YYYY/MM/DD
Range output or input is two dates beside to each other with a separator between them which is rangeSeparator
, default value is #
فرمت ورودی یا خروجی محدوده به صورت دو تاریخ کنار هم با یک جدا کننده است. این ورودی همان جدا کننده است که مقدار پیش فرض آن #
میباشد
String rangeSeparator Default: #
The height of your datepicker
ارتفاع دیت پیکر
double datePickerHeight Default: 320
When you tap on the year caption, a tiny dialog appears with an animation, this option handles the Duration
of appearing the dialog
زمانیکه روی عنوان سال کلیک میکنید، دیالوگ کوچکی ظاهر میشود، این ورودی مدت زمان ظاهر شدن دیالوگ را مشخص میکند
Duration yearSelectionAnimationDuration Default: 400 milliseconds
The year dialog box Curve
type
نوع انیمیشن دیالوگ انتخاب سال
Curve yearSelectionAnimationCurve Default: elasticOut
When you tap on the month caption, a tiny dialog appears with an animation, this option handles the Duration
of appearing the dialog
زمانیکه روی عنوان ماه کلیک میکنید، دیالوگ کوچکی ظاهر میشود، این ورودی مدت زمان ظاهر شدن دیالوگ را مشخص میکند
Duration monthSelectionAnimationDuration Default: 400 milliseconds
The month dialog box Curve
type
نوع انیمیشن دیالوگ انتخاب ماه
Curve monthSelectionAnimationCurve
The background color of selected year in year-selection-dialog
**رنگ پس زمینه سال انتخاب شده در **دیالوگ انتخاب سال
Color yearSelectionBackgroundColor
Text style of year selection dialog box
استایل متن در دیالوگ انتخاب سال
TextStyle yearSelectionTextStyle
The background color of selected year in year selection dialog box
رنگ پس زمینه سال انتخاب شده در دیالوگ انتخاب سال
Color yearSelectionHighlightBackgroundColor
Text style of selected year in year selection dialog box
استایل متن سال انتخاب شده در دیالوگ انتخاب سال
TextStyle yearSelectionHighlightTextStyle
The background color of selected month in year-selection-dialog
**رنگ پس زمینه ماه انتخاب شده در **دیالوگ انتخاب ماه
Color monthSelectionBackgroundColor
Text style of month selection dialog box
استایل متن در دیالوگ انتخاب ماه
TextStyle monthSelectionTextStyle
The background color of selected year in year selection dialog box
رنگ پس زمینه سال انتخاب شده در دیالوگ انتخاب سال
Color monthSelectionHighlightBackgroundColor
Text style of selected month in month selection dialog box
استایل متن ماه انتخاب شده در دیالوگ انتخاب ماه
TextStyle monthSelectionHighlightTextStyle
Background color of week captions
رنگ پس زمینه عناوین هفته
Color weekCaptionsBackgroundColor
Text style of week captions
استایل متن عناوین هفته
TextStyle weekCaptionsTextStyle
Background color of header
رنگ پس زمینه هدر
Color headerBackgroundColor
Text style of header texts, The icons near header captions also take their effect by this option
استایل متن، ماه و سال هدر. آیکون های کنار ماه و سال هم از این پارامتر تاثیر میگیرند
TextStyle headerTextStyle
background color of days
رنگ پس زمینه روزها
Color daysBackgroundColor
Color daysFontColor
Color currentDayBackgroundColor
Color currentDayFontColor
Color selectedDayBackgroundColor
Color selectedDayFontColor
Color headerTodayBackgroundColor
Color disabledDayBackgroundColor
Color disabledDayFontColor
Text headerTodayText
Icon headerTodayIcon
Color daysBorderColor
Color selectedDayBorderColor
Color selectedDaysInnerBorderColor
Color todayBorderColor
double daysBorderWidth
up to this version all output dates are in persian. تا این نسخه تمام تاریخ های خروجی پارسی(جلالی) هستند
rangeSeparator
and your custom date separator should not be equal, otherwise datepicker will return null
مقدار ورودی rangeSeparator
و جداکننده ای که برای فرمت خروجی انتخاب کرده اید نباید یکی باشند در این صورت دیت پیکر خروجی جداکننده های محدوده و خروجی مشابه هستند
برمیگرداند
Persian input dates must respect YYYY/MM/DD
format. output format is up to you
Gregorian input dates must respect YYYY-MM-DD
format. output format is persian and up to you
فرمت تاریخ های ورودی که پارسی (جلالی) هستند باید بصورت
YYYY/MM/DD
باشد. فرمت خروجی به دلخواه شماست
فرمت تاریخ های ورودی که میلادی هستند باید بصورت
YYYY-MM-DD
باشد. فرمت تاریخ خروجی، پارسی و به دلخواه شما خواهد بود
You can find the full example in the Git Repository, example directory
example/example.dart
import 'package:flutter/material.dart';
import 'package:persian_datepicker/persian_datepicker.dart';
void main() {
runApp(Home());
}
class Home extends StatefulWidget {
@override
HomeState createState() {
return new HomeState();
}
}
class HomeState extends State<Home> {
// our text controller
final TextEditingController textEditingController = TextEditingController();
PersianDatePickerWidget persianDatePicker;
@override
void initState() {
/*Simple DatePicker*/
persianDatePicker = PersianDatePicker(
controller: textEditingController,
// datetime: '1397/06/09',
).initialize();
/*Range DatePicker*/
/*persianDatePicker = PersianDatePicker(
controller: textEditingController,
rangeDatePicker: true,
).initialize();*/
/*Gregorian DatePicker*/
/*persianDatePicker = PersianDatePicker(
controller: textEditingController,
gregorianDatetime: '2018-09-08',
outputFormat: 'YYYY/MM/DD',
).initialize();*/
/*Inline DatePicker*/
/*persianDatePicker = PersianDatePicker(
controller: textEditingController,
datetime: '1397/06/19',
outputFormat: 'YYYY/MM/DD',
).initialize();*/
/*Custom Format DatePicker*/
/*persianDatePicker = PersianDatePicker(
controller: textEditingController,
datetime: '1397/06/19',
outputFormat: 'MM - YYYY - DD',
).initialize();*/
/*Customized DatePicker*/
/*persianDatePicker = PersianDatePicker(
controller: textEditingController,
outputFormat: 'YYYY/MM/DD',
datetime: '1397/08/13',
finishDatetime: '1397/08/17',
daysBorderWidth: 3,
weekCaptionsBackgroundColor: Colors.red,
headerBackgroundColor: Colors.blue.withOpacity(0.5),
headerTextStyle: TextStyle(color: Colors.blue, fontSize: 17),
headerTodayText: Text('امروز', style: TextStyle(fontSize: 15),),
headerTodayIcon: Icon(Icons.access_alarm, size: 15,),
datePickerHeight: 280
).initialize();*/
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('تقویم ساده'),),
body: Builder(builder: (BuildContext context) {
return Column(
children: <Widget>[
// Simple Date Picker
Container(
child: persianDatePicker,
),
TextField(
controller: textEditingController,
),
],
);
}),
),
);
}
}
Add this to your package's pubspec.yaml file:
dependencies:
persian_datepicker: ^1.0.9
You can install packages from the command line:
with Flutter:
$ flutter packages get
Alternatively, your editor might support flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:persian_datepicker/persian_datepicker.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.2.1 | Feb 8, 2019 |
|
|
1.2.0 | Feb 7, 2019 |
|
|
1.1.7 | Feb 7, 2019 |
|
|
1.1.6 | Jan 24, 2019 |
|
|
1.1.5 | Jan 21, 2019 |
|
|
1.1.4 | Jan 21, 2019 |
|
|
1.1.3 | Jan 18, 2019 |
|
|
1.1.2 | Jan 18, 2019 |
|
|
1.1.1 | Jan 17, 2019 |
|
|
1.1.0 | Jan 17, 2019 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
70
|
Health:
Code health derived from static analysis.
[more]
|
100
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
100
|
Overall:
Weighted score of the above.
[more]
|
85
|
We analyzed this package on Feb 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Format lib/jalaali_js.dart
.
Run flutter format
to format lib/jalaali_js.dart
.
Format lib/persian_datepicker.dart
.
Run flutter format
to format lib/persian_datepicker.dart
.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.68.0 <3.0.0 | ||
flutter | 0.0.0 | ||
Transitive dependencies | |||
collection | 1.14.11 | ||
meta | 1.1.6 | 1.1.7 | |
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test |