PersianCupertinoDatePicker constructor

PersianCupertinoDatePicker({
  1. Key? key,
  2. PersianCupertinoDatePickerMode mode = PersianCupertinoDatePickerMode.dateAndTime,
  3. required ValueChanged<Jalali> onDateTimeChanged,
  4. Jalali? initialDateTime,
  5. Jalali? minimumDate,
  6. Jalali? maximumDate,
  7. int minimumYear = 1,
  8. int? maximumYear,
  9. int minuteInterval = 1,
  10. bool use24hFormat = false,
  11. DatePickerDateOrder? dateOrder,
  12. Color? backgroundColor,
  13. bool showDayOfWeek = false,
  14. double itemExtent = _kItemExtent,
  15. SelectionOverlayBuilder? selectionOverlayBuilder,
})

Constructs an iOS style date picker.

mode is one of the mode listed in PersianCupertinoDatePickerMode and defaults to PersianCupertinoDatePickerMode.dateAndTime.

onDateTimeChanged is the callback called when the selected date or time changes. When in PersianCupertinoDatePickerMode.time mode, the year, month and day will be the same as initialDateTime. When in PersianCupertinoDatePickerMode.date mode, this callback will always report the start time of the currently selected day. When in PersianCupertinoDatePickerMode.monthYear mode, the day and time will be the start time of the first day of the month.

initialDateTime is the initial date time of the picker. Defaults to the present date and time. The present must conform to the intervals set in minimumDate, maximumDate, minimumYear, and maximumYear.

minimumDate is the minimum selectable Jalali of the picker. When set to null, the picker does not limit the minimum Jalali the user can pick. In PersianCupertinoDatePickerMode.time mode, minimumDate should typically be on the same date as initialDateTime, as the picker will not limit the minimum time the user can pick if it's set to a date earlier than that.

maximumDate is the maximum selectable Jalali of the picker. When set to null, the picker does not limit the maximum Jalali the user can pick. In PersianCupertinoDatePickerMode.time mode, maximumDate should typically be on the same date as initialDateTime, as the picker will not limit the maximum time the user can pick if it's set to a date later than that.

minimumYear is the minimum year that the picker can be scrolled to in PersianCupertinoDatePickerMode.date mode. Defaults to 1.

maximumYear is the maximum year that the picker can be scrolled to in PersianCupertinoDatePickerMode.date mode. Null if there's no limit.

minuteInterval is the granularity of the minute spinner. Must be a positive integer factor of 60.

use24hFormat decides whether 24 hour format is used. Defaults to false.

dateOrder determines the order of the columns inside PersianCupertinoDatePicker in PersianCupertinoDatePickerMode.date and PersianCupertinoDatePickerMode.monthYear mode. When using monthYear mode, both DatePickerDateOrder.dmy and DatePickerDateOrder.mdy will result in the month|year order. Defaults to the locale's default date format/order.

Implementation

PersianCupertinoDatePicker({
  super.key,
  this.mode = PersianCupertinoDatePickerMode.dateAndTime,
  required this.onDateTimeChanged,
  Jalali? initialDateTime,
  this.minimumDate,
  this.maximumDate,
  this.minimumYear = 1,
  this.maximumYear,
  this.minuteInterval = 1,
  this.use24hFormat = false,
  this.dateOrder,
  this.backgroundColor,
  this.showDayOfWeek = false,
  this.itemExtent = _kItemExtent,
  this.selectionOverlayBuilder,
})  : initialDateTime = initialDateTime ?? Jalali.now(),
      assert(
        itemExtent > 0,
        'item extent should be greater than 0',
      ),
      assert(
        minuteInterval > 0 && 60 % minuteInterval == 0,
        'minute interval is not a positive integer factor of 60',
      ) {
  assert(
    mode != PersianCupertinoDatePickerMode.dateAndTime ||
        minimumDate == null ||
        !this.initialDateTime.isBefore(minimumDate!),
    'initial date is before minimum date',
  );
  assert(
    mode != PersianCupertinoDatePickerMode.dateAndTime ||
        maximumDate == null ||
        !this.initialDateTime.isAfter(maximumDate!),
    'initial date is after maximum date',
  );
  assert(
    (mode != PersianCupertinoDatePickerMode.date &&
            mode != PersianCupertinoDatePickerMode.monthYear) ||
        (minimumYear >= 1 && this.initialDateTime.year >= minimumYear),
    'initial year is not greater than minimum year, or minimum year is not positive',
  );
  assert(
    (mode != PersianCupertinoDatePickerMode.date &&
            mode != PersianCupertinoDatePickerMode.monthYear) ||
        maximumYear == null ||
        this.initialDateTime.year <= maximumYear!,
    'initial year is not smaller than maximum year',
  );
  assert(
    (mode != PersianCupertinoDatePickerMode.date &&
            mode != PersianCupertinoDatePickerMode.monthYear) ||
        minimumDate == null ||
        !minimumDate!.isAfter(this.initialDateTime),
    'initial date ${this.initialDateTime} is not greater than or equal to minimumDate $minimumDate',
  );
  assert(
    (mode != PersianCupertinoDatePickerMode.date &&
            mode != PersianCupertinoDatePickerMode.monthYear) ||
        maximumDate == null ||
        !maximumDate!.isBefore(this.initialDateTime),
    'initial date ${this.initialDateTime} is not less than or equal to maximumDate $maximumDate',
  );
  assert(
    this.initialDateTime.minute % minuteInterval == 0,
    'initial minute is not divisible by minute interval',
  );
}