configDefaultValue method

void configDefaultValue()

Implementation

void configDefaultValue() {
  if (children.isNotEmpty) {
    for (SelectionEntity entity in children) {
      if (!PhoenixTools.isEmpty(defaultValue)) {
        List<String> values = defaultValue!.split(',');
        entity.isSelected = values.contains(entity.value);
      }
    }

    /// 当 default 不在普通 Item 类型中时,尝试填充 同级别 Range Item.
    if (children.where((_) => _.isSelected).toList().isEmpty) {
      List<SelectionEntity> rangeItems = children.where((_) {
        return (_.filterType == SelectionFilterType.range ||
            _.filterType == SelectionFilterType.dateRange ||
            _.filterType == SelectionFilterType.dateRangeCalendar);
      }).toList();
      SelectionEntity? rangeEntity;
      if (rangeItems.isNotEmpty) {
        rangeEntity = rangeItems[0];
      }
      if (rangeEntity != null && !PhoenixTools.isEmpty(defaultValue)) {
        List<String> values = defaultValue!.split(':');
        if (values.length == 2 &&
            int.tryParse(values[0]) != null &&
            int.tryParse(values[1]) != null) {
          rangeEntity.customMap = {};
          rangeEntity.customMap = {"min": values[0], "max": values[1]};
          rangeEntity.isSelected = true;
        }
      }
    }

    for (SelectionEntity entity in children) {
      entity.configDefaultValue();
    }
    if (hasCheckBoxBrother()) {
      isSelected = children.where((_) => _.isSelected).isNotEmpty;
    } else {
      isSelected =
          isSelected || children.where((_) => _.isSelected).isNotEmpty;
    }
  }
}