jalali_calendar 1.0.3+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

Jalali/Shamsi Calendar Datepicker and TimePicker #

Calendar , Datepicker and Date Convertor For Persian Date(Jalali/Shamsi date) with holiday for Android and Ios

Based on Material Flutter DatePicker And TimePicker

Usage #

Import this line in Flutter pubspec #

jalali_calendar: <Last Version>

To Use Calendar Or DatePicker , Import this line to your dart file #

import 'package:jalali_calendar/jalali_calendar.dart';

To Use date Convertor , Import this line to your dart file #

import 'package:persian_date/persian_date.dart';

After import library, to show the calendar you can use jalaliCalendarPicker() constructor method , on the constructor context is important if you want to return the selected date to Gregorian, on the constructor set the convertToGregorian to true

This sample return the selected date as Jalali(شمسی) #

Future _selectDate() async {
    String picked = await jalaliCalendarPicker(context: context); // نمایش خروجی به صورت شمسی
   //  await jalaliCalendarPicker(context: context,convertToGregorian: true); // نمایش خروجی به صورت میلادی
    if (picked != null) setState(() => _value =picked.toString());
    print(_value);
  }

This sample return the selected date as Gregorian(میلادی) #

Future _selectDate() async {
    String picked = await jalaliCalendarPicker(context: context,convertToGregorian: true); // نمایش خروجی به صورت میلادی
    if (picked != null) setState(() => _value =picked.toString());
    print(_value);
  }

Those parameters using To Show the TimePicker #

Parameteroperation
showTimePickerTo show TimePicker set it true
hore24FormatTo return time in 24 hours format set it true
initialTimeTo set initial time use it with TimeOfDay

To use datePicker you can follow this sample #

To show DatePicker those parameters is required

minYear // min date this required  for the start year in Jalali
maxYear // max  date this required  for the last year in jalali
confirm and cancel // widget for show text
_format // for returning date like String _format = 'yyyy-mm-dd';
onChanged // return date when the user changes the date
onConfirm //  return date when the user click confirm

For set, default date use those parameters

initialYear => for year
initialMonth => for month
initialDay => for day

Full datePicker Sample #

    DatePicker.showDatePicker(
      context,
      minYear: 1300,
      maxYear: 1450,
      confirm: Text(
        'Confirm',
        style: TextStyle(color: Colors.red),
      ),
      cancel: Text(
        'Cancel',
        style: TextStyle(color: Colors.cyan),
      ),
      dateFormat: _format,
      onChanged: (year, month, day) {
        if (!showTitleActions) {
          _changeDatetime(year, month, day);
        }
      },
      onConfirm: (year, month, day) {
        _changeDatetime(year, month, day);
        _valuePiker = " Full date : $_datetime  \n year : $year \n  Month  :   $month \n  day :  $day";
      }
    )

 void _changeDatetime(int year, int month, int day) {
    setState(() {
      _datetime = '$year-$month-$day';
    });
  }

To use date Convertor you can follow this sample #

first import this library to your code

import 'package:persian_date/persian_date.dart';

Full Date Convertor Sample #

PersianDate pDate = PersianDate(gregorian: "1989-01-29");
    print("Now ${pDate.getDate}");
    
    PersianDate persianDate = PersianDate();
    print("Now ${persianDate.now}");
    print(persianDate.hour);
    print("year ${persianDate.year}");
    print("isHoliday ${persianDate.isHoliday}");
    print("isHoliday ${persianDate.weekdayname}");
    print(persianDate.monthname); // نام ماه
      print(persianDate.month); // ماه
      print(persianDate.day); // روز
      print(persianDate.hour);// ساعت
      print(persianDate.minute);// دقیقه
      print(persianDate.second);// ثانیه
      print(persianDate.millisecond); // میلی ثانیه
      print(persianDate.microsecond);//


print("Parse Gregorian To Jalali ${persianDate.gregorianToJalali("2019-02-20T00:19:54.000Z","yyyy-m-d hh:nn")}"); 
print("Parse Jalali To Gregorian ${persianDate.jalaliToGregorian("1368-05-30 19:54", "yyyy-m-d hh:nn")}"); 

those formats are supported in date converter #

   `"2012-02-27 13:27:00"`
    `"2012-02-27 13:27:00.123456z"`
    `"2012-02-27 13:27:00,123456z"`
    `"20120227 13:27:00"`
    `"20120227T132700"`
    `"20120227"`
    `"+20120227"`
    `"2012-02-27T14Z"`
    `"2012-02-27T14+00:00"`
    `"-123450101 00:00:00 Z"`: in the year -12345.
    `"2002-02-27T14:00:00-0500"`: Same as `"2002-02-27T19:00:00Z"`
FormatoperationFormatoperation
yyyyreturn year with Four numberhhhours with two number
yyreturn year with two numberhhours with one number
mmreturn month with two numberHHhours with two number in 24
mreturn month with one numberHhours with one number in 24
MMthe month name with full letternnminut with two number
Mthe month name with short formnminut with one number
ddthe day with two numberssSecond with two number
dthe day with one numbersSecond with one number
wweek numberSSshow milliSecond
DDthe day name with full letterSshow milliSecond
Dthe day name with short formuuushow microsecond
amShow time in shortushow microsecond
AMShow full time..

bug report #

Contact me if you have any problems with this library or have any suggestion [tracker]:j.zobeidi89@gmail.com

1.0.3+1 #

  • format code

1.0.3 #

  • Fixed displayed month bug

1.0.2 #

  • delete print method from lib

1.0.1 #

  • Update Some code

1.0.0 #

  • Fixed Selected Day
  • Relpace intl package with jiffy
  • Migrate to Androidx

0.1.6+2 #

  • Fixed Bug

0.1.6+1 #

  • Fixed TimePicker

0.1.6 #

  • Add TimePicker

0.1.5 #

  • Update Some Code And ReadMe File

0.1.4 #

  • Update Some Code

0.1.3 #

  • Update and fixed Some Code

0.1.2 #

  • Update and fixed Some Code
  • returned date in Gregorian
  • fixed bug on some devices

0.1.1 #

  • fixed Bug

0.1.0 #

  • fixed Bug

0.0.2 #

  • fixed Bug

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:jalali_calendar/jalali_calendar.dart';
import 'package:persian_date/persian_date.dart';

void main() {
  runApp(new MaterialApp(
    home: new MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  @override
  _State createState() => new _State();
}

class _State extends State<MyApp> {
  PersianDate persianDate = PersianDate(format: "yyyy/mm/dd  \n DD  , d  MM  ");
  String _datetime = '';
  String _format = 'yyyy-mm-dd';
  String _value = '';
  String _valuePiker = '';
  DateTime selectedDate = DateTime.now();

  Future _selectDate() async {
    String picked = await jalaliCalendarPicker(
        context: context,
        convertToGregorian: false,
        showTimePicker: true,
        hore24Format: true);
    if (picked != null) setState(() => _value = picked);
  }

  @override
  void initState() {
    super.initState();
    print(
        "Parse TO Format ${persianDate.gregorianToJalali("2019-02-20T00:19:54.000Z", "yyyy-m-d hh:nn")}");
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Persain Date'),
        centerTitle: true,
      ),
      body: new Container(
        child: Column(
          children: <Widget>[
            Center(
              child: Column(
                children: <Widget>[
                  Text('  مبدّل تاریخ و زمان ,‌ تاریخ هجری شمسی '),
                  Text(' تقویم شمسی '),
                  Text('date picker شمسی '),
                  new RaisedButton(
                    onPressed: _selectDate,
                    child: new Text('نمایش تقویم'),
                  ),
                  new RaisedButton(
                    onPressed: _showDatePicker,
                    child: new Text('نمایش دیت پیکر'),
                  ),
                  Text(
                    "\nزمان و تاریخ فعلی سیستم :  ${persianDate.now}",
                    textAlign: TextAlign.center,
                    textDirection: TextDirection.rtl,
                  ),
                  Divider(),
                  Text(
                    "تقویم ",
                    textAlign: TextAlign.center,
                  ),
                  Text(
                    _value,
                    textAlign: TextAlign.center,
                  ),
                  Divider(),
                  Text(
                    _valuePiker,
                    textAlign: TextAlign.center,
                  ),
                ],
              ),
            )
            // Expanded(child: ShowCalender())
          ],
        ),
      ),
    );
  }

  /// Display date picker.
  void _showDatePicker() {
    final bool showTitleActions = false;
    DatePicker.showDatePicker(context,
        minYear: 1300,
        maxYear: 1450,
/*      initialYear: 1368,
      initialMonth: 05,
      initialDay: 30,*/
        confirm: Text(
          'تایید',
          style: TextStyle(color: Colors.red),
        ),
        cancel: Text(
          'لغو',
          style: TextStyle(color: Colors.cyan),
        ),
        dateFormat: _format, onChanged: (year, month, day) {
      if (!showTitleActions) {
        _changeDatetime(year, month, day);
      }
    }, onConfirm: (year, month, day) {
      _changeDatetime(year, month, day);
      _valuePiker =
          " تاریخ ترکیبی : $_datetime  \n سال : $year \n  ماه :   $month \n  روز :  $day";
    });
  }

  void _changeDatetime(int year, int month, int day) {
    setState(() {
      _datetime = '$year-$month-$day';
    });
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  jalali_calendar: ^1.0.3+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:jalali_calendar/jalali_calendar.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
82
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [jalali_calendar] that is in a package requiring null.

Health suggestions

Fix lib/src/jalalicalendarpicker.dart. (-4.89 points)

Analysis of lib/src/jalalicalendarpicker.dart reported 10 hints, including:

line 89 col 48: 'display1' is deprecated and shouldn't be used. This is the term used in the 2014 version of material design. The modern term is headline4. This feature was deprecated after v1.13.8..

line 92 col 25: 'subhead' is deprecated and shouldn't be used. This is the term used in the 2014 version of material design. The modern term is subtitle1. This feature was deprecated after v1.13.8..

line 452 col 51: 'body1' is deprecated and shouldn't be used. This is the term used in the 2014 version of material design. The modern term is bodyText2. This feature was deprecated after v1.13.8..

line 460 col 49: 'body2' is deprecated and shouldn't be used. This is the term used in the 2014 version of material design. The modern term is bodyText1. This feature was deprecated after v1.13.8..

line 464 col 43: 'body1' is deprecated and shouldn't be used. This is the term used in the 2014 version of material design. The modern term is bodyText2. This feature was deprecated after v1.13.8..

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (jiffy).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
jiffy ^2.2.0 2.2.0 3.0.1
persian_date ^0.1.5 0.1.5
Transitive dependencies
collection 1.14.12 1.14.13
intl 0.16.1
meta 1.1.8
path 1.7.0
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test