PCupertinoDatePicker constructor

PCupertinoDatePicker({
  1. Key? key,
  2. PCupertinoDatePickerMode mode = PCupertinoDatePickerMode.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. Color? backgroundColor,
})

Constructs an iOS style date picker.

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

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

initialDateTime is the initial date time of the picker. Defaults to the present date and time and must not be null. 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 PCupertinoDatePickerMode.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 PCupertinoDatePickerMode.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 PCupertinoDatePickerMode.date mode. Defaults to 1 and must not be null.

maximumYear is the maximum year that the picker can be scrolled to in PCupertinoDatePickerMode.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.

Implementation

PCupertinoDatePicker({
  Key? key,
  this.mode = PCupertinoDatePickerMode.dateAndTime,
  required this.onDateTimeChanged,
  Jalali? initialDateTime,
  this.minimumDate,
  this.maximumDate,
  this.minimumYear = 1,
  this.maximumYear,
  this.minuteInterval = 1,
  this.use24hFormat = false,
  this.backgroundColor,
})  : initialDateTime = initialDateTime ?? Jalali.now(),
      assert(
        minuteInterval > 0 && 60 % minuteInterval == 0,
        'minute interval is not a positive integer factor of 60',
      ),
      super(key: key) {
  assert(
    mode != PCupertinoDatePickerMode.dateAndTime ||
        minimumDate == null ||
        !this.initialDateTime.isBefore(minimumDate!),
    'initial date is before minimum date',
  );
  assert(
    mode != PCupertinoDatePickerMode.dateAndTime ||
        maximumDate == null ||
        !this.initialDateTime.isAfter(maximumDate!),
    'initial date is after maximum date',
  );
  assert(
    mode != PCupertinoDatePickerMode.date ||
        (minimumYear >= 1 && this.initialDateTime.year >= minimumYear),
    'initial year is not greater than minimum year, or minimum year is not positive',
  );
  assert(
    mode != PCupertinoDatePickerMode.date ||
        maximumYear == null ||
        this.initialDateTime.year <= maximumYear!,
    'initial year is not smaller than maximum year',
  );
  assert(
    mode != PCupertinoDatePickerMode.date ||
        minimumDate == null ||
        !minimumDate!.isAfter(this.initialDateTime),
    'initial date ${this.initialDateTime} is not greater than or equal to minimumDate $minimumDate',
  );
  assert(
    mode != PCupertinoDatePickerMode.date ||
        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',
  );
}