jalaliCalendarPicker function

Future<String?> jalaliCalendarPicker({
  1. required BuildContext context,
  2. SelectableDayPredicate? selectableDayPredicate,
  3. DatePickerMode initialDatePickerMode = DatePickerMode.day,
  4. String? selectedFormat,
  5. bool? toArray,
  6. Locale? locale,
  7. TextDirection textDirection = TextDirection.rtl,
  8. bool convertToGregorian = false,
  9. bool showTimePicker = false,
  10. bool hore24Format = false,
  11. TimeOfDay? initialTime,
})

Shows a dialog containing a material design date picker.

The returned Future resolves to the date selected by the user when the user closes the dialog. If the user cancels the dialog, null is returned.

An optional selectableDayPredicate function can be passed in to customize the days to enable for selection. If provided, only the days that selectableDayPredicate returned true for will be selectable.

An optional initialDatePickerMode argument can be used to display the date picker initially in the year or month+day picker mode. It defaults to month+day, and must not be null.

An optional locale argument can be used to set the locale for the date picker. It defaults to the ambient locale provided by Localizations.

An optional textDirection argument can be used to set the text direction (RTL or LTR) for the date picker. It defaults to the ambient text direction provided by Directionality. If both locale and textDirection are not null, textDirection overrides the direction chosen for the locale.

The context argument is passed to showDialog, the documentation for which discusses how it is used.

See also:

Implementation

Future<String?> jalaliCalendarPicker({
  required BuildContext context,
  SelectableDayPredicate? selectableDayPredicate,
  DatePickerMode initialDatePickerMode = DatePickerMode.day,
  String? selectedFormat,
  bool? toArray,
  Locale? locale,
  TextDirection textDirection = TextDirection.rtl,
  bool convertToGregorian = false,
  bool showTimePicker = false,
  bool hore24Format = false,
  TimeOfDay? initialTime,
}) async {
  DateTime initialDate = DateTime.now();
  DateTime firstDate = DateTime(1700);
  DateTime lastDate = DateTime(2200);

  assert(!initialDate.isBefore(firstDate),
      'initialDate must be on or after firstDate');
  assert(!initialDate.isAfter(lastDate),
      'initialDate must be on or before lastDate');
  assert(
      !firstDate.isAfter(lastDate), 'lastDate must be on or after firstDate');
  assert(selectableDayPredicate == null || selectableDayPredicate(initialDate),
      'Provided initialDate must satisfy provided selectableDayPredicate');
  assert(
      initialDatePickerMode != null, 'initialDatePickerMode must not be null');
  assert(context != null);
  assert(debugCheckHasMaterialLocalizations(context));

  Widget child = _DatePickerDialog(
    initialDate: initialDate,
    firstDate: firstDate,
    lastDate: lastDate,
    selectableDayPredicate: selectableDayPredicate,
    initialDatePickerMode: initialDatePickerMode,
    selectedFormat: selectedFormat ?? "yyyy-mm-dd HH:nn:ss",
    hore24Format: hore24Format,
    showTimePicker: showTimePicker,
    convertToGregorian: convertToGregorian,
    initialTime: initialTime ?? TimeOfDay.now(),
  );

  if (textDirection != null) {
    child = Directionality(
      textDirection: textDirection,
      child: child,
    );
  }

  if (locale != null) {
    child = Localizations.override(
      context: context,
      locale: locale,
      child: child,
    );
  }

  return await showDialog<String>(
    context: context,
    builder: (BuildContext context) => child,
  );
}