dateRangePicker static method

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

pick date range with customization

Implementation

static dateRangePicker(
    {required BuildContext context,
    required Function(String fromDate, String toDate) onSelected,
    String? fromDate,
    String? toDate,
    String? minDate,
    String? maxDate,
    String format = Format.fyyyyMMdd}) {
  String startDate = _isNullOrEmpty(fromDate)
      ? getCurrentDate()
      : dateTimeFormat(
          dateTime: fromDate!, inFormat: format, outFormat: format);
  String endDate = _isNullOrEmpty(toDate)
      ? getCurrentDate()
      : dateTimeFormat(
          dateTime: toDate!, inFormat: format, outFormat: format);
  if (!validDateTimeRange(
      fromDateTime: startDate, toDateTime: endDate, format: format)) {
    startDate = getCurrentDate();
    endDate = getCurrentDate();
  }
  showDateRangePicker(
      context: context,
      firstDate: _isNullOrEmpty(minDate)
          ? DateTime(1950)
          : stringToDateTime(date: minDate!),
      lastDate: _isNullOrEmpty(maxDate)
          ? DateTime(3000)
          : stringToDateTime(date: maxDate!),
      initialDateRange: DateTimeRange(
        start: stringToDateTime(date: startDate),
        end: stringToDateTime(date: endDate),
      )).then((value) {
    String fDate = "";
    String tDate = "";
    if (value != null) {
      fDate = dateTimeToString(date: value.start, format: format);
      tDate = dateTimeToString(date: value.end, format: format);
    } else {
      fDate = _isNullOrEmpty(fromDate)
          ? ""
          : dateTimeFormat(
              dateTime: fromDate!, inFormat: format, outFormat: format);
      tDate = _isNullOrEmpty(toDate)
          ? ""
          : dateTimeFormat(
              dateTime: toDate!, inFormat: format, outFormat: format);
    }
    onSelected(fDate, tDate);
  });
}