How can I modify sorting algorithm for color and sizes without hardcode?

I have a code that checks the availability of attributes. That is, if there is a black color with sizes s, l, xl and m, and there is a purple color with size s, then block unavailable size combinations for purple. However, both colors have a common size s. Also, the user can immediately select the black color on the product card and go to the detailed card where he can select other combinations of sizes and colors. And in this case, if the user selected the black color size M and went to the card, but the size s is blocked, then switching to purple will be blocked. There is a direct dependency between what the user initially selected and which common elements are unavailable for selection. I wrote code that checks the availability of colors and sizes and blocks unavailable non-common combinations, but how to get rid of the hardcode? This approach is not flexible.

An approximate structure from which I create my algorithm, so that it is clearer what I mean

[{“name”: “Purple”,”characteristics”: [{“name”: “dress_size”,”value”: “S”},{“name”: “color”,”value”: “Purple”}],{“name”: “black, size XL”,”characteristics”: [{“name”: “dress_size”,”value”: “XL”},{“name”: “color”,”value”: “Black”}],{“name”: “black, size L”,”characteristics”: [{“name”: “dress_size”,”value”: “L”},{“name”: “color”,”value”: “Black”}],{“name”: “black, size M”,”characteristics”: [{“name”: “dress_size”,”value”: “M”}{“name”: “color”,”value”: “Black”}],{“name”: “black, size C”,”characteristics”: [{“name”: “dress_size”,”value”: “S”}{“name”: “color”,”value”: “Black”}],]

also my code in which I rely on sizes and colors, but it is not flexible and will no longer work if something is added or changed final Map<CharacteristicEnum, Set<String>> availableAttributes;

bool isAttributeAvailable(CharacteristicEnum characteristic, String value) {
    final Map<CharacteristicEnum, String> selectedAttributes = selectedAttributeMap;

    final Iterable<ProductDetailsModel>? availableProducts = productOffer.value?.where((ProductDetailsModel product) {
      return selectedAttributes.entries.every((MapEntry<CharacteristicEnum, String> entry) {
        if (entry.key == characteristic) return true;
        final List<String>? attributeValues = product.groupedCharacteristics[entry.key];

        return attributeValues != null && attributeValues.contains(entry.value);
      });
    });

    if (availableProducts != null && availableProducts.isNotEmpty) {
      for (final ProductDetailsModel product in availableProducts) {
        final List<String>? availableValues = product.groupedCharacteristics[characteristic];
        if (availableValues != null && availableValues.contains(value)) {
          return true;
        }
      }
    }

    if (characteristic == CharacteristicEnum.color) {
      return _canSwitchToAvailableAttribute(characteristic, value);
    }

    return false;
  }

  bool _canSwitchToAvailableAttribute(CharacteristicEnum characteristic, String value) {
    for (final ProductDetailsModel product in productOffer.value ?? <ProductDetailsModel>[]) {
      final List<String>? availableValues = product.groupedCharacteristics[characteristic];
      if (availableValues != null && availableValues.contains(value)) {
        return true;
      }
    }

    return false;
  }
  onAsync<SelectAttributeProductDetailEvent>((SelectAttributeProductDetailEvent event) async* {
      final Map<CharacteristicEnum, String> selectedMap = state.selectedAttributeMap.copy();

      selectedMap[event.nameAttribute] = event.attributeValue;

      if (event.nameAttribute == CharacteristicEnum.color) {
        final Iterable<String>? availableSizesForNewColor = state.productOffer.value
            ?.where(
              (ProductDetailsModel product) =>
                  product.groupedCharacteristics[CharacteristicEnum.color]?.contains(event.attributeValue) ?? false,
            )
            .expand(
              (ProductDetailsModel product) =>
                  product.groupedCharacteristics[CharacteristicEnum.dressSize] ?? <String>[],
            );

        final String? currentSize = selectedMap[CharacteristicEnum.dressSize];
        if (currentSize == null ||
            (availableSizesForNewColor != null && !availableSizesForNewColor.contains(currentSize))) {
          if (availableSizesForNewColor != null && availableSizesForNewColor.isNotEmpty) {
            selectedMap[CharacteristicEnum.dressSize] = availableSizesForNewColor.first;
          }
        }
      }

      final Map<CharacteristicEnum, Set<String>> availableAttributes = <CharacteristicEnum, Set<String>>{};

      for (final CharacteristicEnum characteristic in state.groupedCharacteristics.keys) {
        availableAttributes[characteristic] = state.groupedCharacteristics[characteristic]
                ?.where((String value) => state.isAttributeAvailable(characteristic, value))
                .toSet() ??
            <String>{};
      }

      yield state.copyWith(
        selectedAttributeMap: selectedMap,
        availableAttributes: availableAttributes,
      );
    });
  }

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật