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)
      ? getCurrentDateTime()
      : stringFormat(date: fromDate!, format: format);
  String endDate = _isNullOrEmpty(toDate)
      ? getCurrentDateTime()
      : stringFormat(date: toDate!, format: format);
  if (!validDateTimeRange(fromDateTime: startDate, toDateTime: endDate)) {
    startDate = getCurrentDateTime();
    endDate = getCurrentDateTime();
  }
  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)
          ? ""
          : stringFormat(date: fromDate!, format: format);
      tDate = _isNullOrEmpty(toDate)
          ? ""
          : stringFormat(date: toDate!, format: format);
    }
    onSelected(fDate, tDate);
  });
}