datePicker static method

dynamic datePicker({
  1. required BuildContext context,
  2. required dynamic onSelected(
    1. String date
    ),
  3. String? date,
  4. String? minDate,
  5. String? maxDate,
  6. String format = Format.fyyyyMMdd,
})

pick date with customization

Implementation

static datePicker(
    {required BuildContext context,
    required Function(String date) onSelected,
    String? date,
    String? minDate,
    String? maxDate,
    String format = Format.fyyyyMMdd}) {
  showDatePicker(
    context: context,
    initialDate:
        _isNullOrEmpty(date) ? DateTime.now() : stringToDateTime(date: date!),
    firstDate: _isNullOrEmpty(minDate)
        ? DateTime(1950)
        : stringToDateTime(date: minDate!),
    lastDate: _isNullOrEmpty(maxDate)
        ? DateTime(3000)
        : stringToDateTime(date: maxDate!),
  ).then((value) {
    String selectedDate = "";
    if (value != null) {
      selectedDate = dateTimeToString(date: value, format: format);
    } else {
      selectedDate = _isNullOrEmpty(date)
          ? ""
          : formatDateTime(
              dateTime: date!, inFormat: format, outFormat: format);
    }
    onSelected(selectedDate);
  });
}