persian_datetime_picker 1.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 80

A persian (farsi,shamsi) datetime picker for flutter, inspired by material datetime picker. #

pub package

A Flutter persian datetime picker inspired by material datetime picker and based on shamsi_date.

You can pick date / range date / time / date and time.

Screenshots #

Date pickerTime pickerRange Date pickerYear pickerMonth picker

Usage #

Add it to your pubspec.yaml file:


dependencies:

persian_datetime_picker: version

In your library add the following import:


import  'package:persian_datetime_picker/persian_datetime_picker.dart';

Here is an example how to use:


void  main() => runApp(new  MyApp());

  

class  MyApp  extends  StatelessWidget {

  @override

  Widget  build(BuildContext context) {

    return  new  MaterialApp(

      title: 'Persian datetime picker',

      home: new  MyHomePage(),

    );

    }

}

  

class  MyHomePage  extends  StatefulWidget {

  MyHomePage({Key key, this.title}) : super(key: key);

    

  @override

  _MyHomePageState  createState() => new  _MyHomePageState();

}

  

class  _MyHomePageState  extends  State<MyHomePage> {

  

  void  _showDateTimePicker() {

    showDialog(

      context: context,

      builder: (BuildContext _) {

        return  PersianDateTimePicker(

          initial: '1398/03/20 19:50',

          type: 'datetime',

          onSelect: (date) {

            print(date);

          },

      );

      },

    );

  }

  

  @override

  Widget  build(BuildContext context) {

    return  new  Directionality(

      textDirection: TextDirection.rtl,

      child: Scaffold(

        appBar: new  AppBar(

          title: new  Text('Persian Datetime Picker'),

        ),

        body: new  Center(

          child: Column(

            children: <Widget>[

              RaisedButton(

                onPressed: () {

                _showDateTimePicker();

                },

                child: Text('تاریخ زمان'),

              ),

            ],

          ),

        ),

      ),

    );

  }

}

You must make dialog like below:


void  _showDateTimePicker() {

  showDialog(

    context: context,

    builder: (BuildContext _) {

      return  PersianDateTimePicker(

        type: 'datetime',//optional ,default value is date.

        initial: '1398/03/20 19:50',//optional

        onSelect: (date) {

          print(date);

        },

      );

    },

  );

}

And after that you can open dialog when call an event:


onPressed: () {

  _showDateTimePicker();

},

Date time picker parameters and events #

ParameterTypeDefaultDescription
initialStringnullInitial picker with a date or time
typeStringdateHas six value(date,time,datetime,rangedate,year,month)
disableString or List<String>nullDisable dates or time
colorColorColors.blueAccentPicker theme color
minStringnullMinimom Date
maxStringnullMaximom Date
onSelectFunction(String)This event return a String date or time

You have six value for type parameter .

  • datetime : when choose datetime type initial parameter must be like '1398/03/20 19:50' format.
  • date : when choose date type initial parameter must be like '1398/03/20' format.
  • rangedate : when choose rangedate type initial parameter must be like '1398/03/20 # 1398/03/20' format.
  • time : when choose time type initial parameter must be like '19:50' format.

  • year: when choose year type initial parameter must be like '1398' format.

  • month: when choose month type initial parameter must be like '03' format.

##Pull request and feedback are always appreciated. ###Contact me with mem.amir.m@gmail.com.

[0.0.1] - TODO: Add release date. #

[1.0.0] - Add year picker and month picker, add disable feature,fix bugs. #

[1.0.1] - Add theme color ,fix bugs. #

[1.0.2] - Add min and max date. #

[1.0.3] - Fix disabled dates in release mode. #

[1.0.4] - Fix Bugs. #

[1.0.5] - Fix Time Picker Bugs. #

[1.0.6] - Remove flushbar package. #

[1.0.7] - Update shamsi_date version. #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:persian_datetime_picker/persian_datetime_picker.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  final ThemeData androidTheme = new ThemeData(
      fontFamily: 'is',
      primaryColorDark: Color(0xFF185a9d),
      primaryColorLight: Color(0xFF43cea2),
      accentColor: Color(0xFF43cea2),
      primaryColor: Colors.white,
      primaryTextTheme: TextTheme(caption: TextStyle(fontSize: 12.0)));

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: androidTheme,
      home: new MyHomePage(title: 'دیت تایم پیکر فارسی'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String label;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    label = 'انتخاب تاریخ زمان';
  }

  void _showDateTimePicker() {
    showDialog(
      context: context,
      builder: (BuildContext _) {
        return PersianDateTimePicker(
          initial: '1398/03/20 19:50',
          type: 'datetime',
          color: Colors.redAccent,
          onSelect: (date) {
            setState(() {
              label = date;
            });
          },
        );
      },
    );
  }

  void _showDatePicker() {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext _) {
        return PersianDateTimePicker(
          initial: '1398/11/20',
          disable: ['friday', '1398/11/21', '13985/3/21'],
          // min:"1398/11/12",
          // max:"1398/11/25",
          type: 'date',
          onSelect: (date) {
            setState(() {
              label = date;
            });
          },
        );
      },
    );
  }

  void _showYearPicker() {
    showDialog(
      context: context,
      builder: (BuildContext _) {
        return PersianDateTimePicker(
          initial: '1397',
          type: 'year',
          disable: ['1400', '1395'],
          onSelect: (date) {
            setState(() {
              label = date;
            });
          },
        );
      },
    );
  }

  void _showMonthPicker() {
    showDialog(
      context: context,
      builder: (BuildContext _) {
        return PersianDateTimePicker(
          initial: '03',
          disable: ['2','03'],
          type: 'month',
          onSelect: (date) {
            setState(() {
              label = date;
            });
          },
        );
      },
    );
  }

  void _showTimePicker() {
    showDialog(
      context: context,
      builder: (BuildContext _) {
        return PersianDateTimePicker(
          initial: '19:50',
          // disable: ['20:50','20:51','20:55'],
          type: 'time',
          onSelect: (date) {
            setState(() {
              label = date;
            });
          },
        );
      },
    );
  }

  void _showRangeDatePicker() {
    showDialog(
      context: context,
      builder: (BuildContext _) {
        return PersianDateTimePicker(
          initial: '1398/03/22#1399/03/25',
          type: 'rangedate',
          color: Colors.orangeAccent,
          onSelect: (date) {
            setState(() {
              label = date;
            });
          },
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Directionality(
      textDirection: TextDirection.rtl,
      child: Scaffold(
        appBar: new AppBar(
          title: new Text(widget.title,style: TextStyle(fontFamily: 'IS'),),
        ),
        body: new Center(
          child: Column(
            children: <Widget>[
              RaisedButton(
                onPressed: () {
                  _showDateTimePicker();
                },
                child: Text('تاریخ زمان'),
              ),
              RaisedButton(
                onPressed: () {
                  _showDatePicker();
                },
                child: Text('تاریخ '),
              ),
              RaisedButton(
                onPressed: () {
                  _showYearPicker();
                },
                child: Text('سال '),
              ),
              RaisedButton(
                onPressed: () {
                  _showMonthPicker();
                },
                child: Text('ماه '),
              ),
              RaisedButton(
                onPressed: () {
                  _showRangeDatePicker();
                },
                child: Text('بازه تاریخ '),
              ),
              RaisedButton(
                onPressed: () {
                  _showTimePicker();
                },
                child: Text(' زمان'),
              ),
              Text(label)
            ],
          ),
        ),
        floatingActionButton: new FloatingActionButton(
          onPressed: () {
            _showDatePicker();
          },
          tooltip: 'Increment',
          child: new Icon(Icons.add),
        ), // This trailing comma makes auto-formatting nicer for build methods.
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  persian_datetime_picker: ^1.0.7

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:persian_datetime_picker/persian_datetime_picker.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
80
Health:
Code health derived from static analysis. [more]
67
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
80
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 [persian_datetime_picker] that is in a package requiring null.

Health issues and suggestions

Fix lib/widget/dialog.dart. (-27.95 points)

Analysis of lib/widget/dialog.dart reported 6 warnings, 4 hints, including:

line 332 col 7: Missing case clause for 'linux'.

line 332 col 7: Missing case clause for 'macOS'.

line 332 col 7: Missing case clause for 'windows'.

line 617 col 7: Missing case clause for 'linux'.

line 617 col 7: Missing case clause for 'macOS'.

Fix lib/date_picker.dart. (-1.49 points)

Analysis of lib/date_picker.dart reported 3 hints:

line 21 col 7: Don't explicitly initialize variables to null.

line 22 col 7: Don't explicitly initialize variables to null.

line 115 col 11: The value of the local variable 'day' isn't used.

Fix lib/utils/consts.dart. (-1.49 points)

Analysis of lib/utils/consts.dart reported 3 hints:

line 7 col 14: Don't explicitly initialize variables to null.

line 8 col 14: Don't explicitly initialize variables to null.

line 9 col 14: Don't explicitly initialize variables to null.

Fix additional 8 files with analysis or formatting issues. (-4.49 points)

Additional issues in the following files:

  • lib/year_picker.dart (3 hints)
  • lib/handle_picker.dart (2 hints)
  • lib/persian_datetime_picker.dart (2 hints)
  • lib/utils/date.dart (1 hint)
  • lib/widget/snack_bar.dart (1 hint)
  • lib/month_picker.dart (Run flutter format to format lib/month_picker.dart.)
  • lib/widget/partition.dart (Run flutter format to format lib/widget/partition.dart.)
  • lib/widget/render_table.dart (Run flutter format to format lib/widget/render_table.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
shamsi_date ^0.8.1 0.8.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test