isValidRange method

bool isValidRange()

校验 range 类型的数据是否合法

Implementation

bool isValidRange() {
  if (filterType == SelectionFilterType.range ||
      filterType == SelectionFilterType.dateRange ||
      filterType == SelectionFilterType.dateRangeCalendar) {
    DateTime minTime = DateTime.parse(datePickerMinDatetime);
    DateTime maxTime = DateTime.parse(datePickerMaxDatetime);
    int limitMin = int.tryParse(extMap['min']?.toString() ?? "") ??
        (filterType == SelectionFilterType.dateRange ||
                filterType == SelectionFilterType.dateRangeCalendar
            ? minTime.millisecondsSinceEpoch
            : 0);
    // 日期最大值没设置 默认是2121年01月01日 08:00:00
    int limitMax = int.tryParse(extMap['max']?.toString() ?? "") ??
        (filterType == SelectionFilterType.dateRange ||
                filterType == SelectionFilterType.dateRangeCalendar
            ? maxTime.millisecondsSinceEpoch
            : 9999);

    if (customMap != null && customMap!.isNotEmpty) {
      String min = customMap!['min'] ?? "";
      String max = customMap!['max'] ?? "";
      if (min.isEmpty && max.isEmpty) {
        return true;
      }
      int? inputMin = int.tryParse(customMap!['min'] ?? "");
      int? inputMax = int.tryParse(customMap!['max'] ?? "");

      if (inputMax != null && inputMin != null) {
        if (inputMin >= limitMin &&
            inputMax <= limitMax &&
            inputMax >= inputMin) {
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    }
  }
  return true;
}