arcoTreeGetAllCheckedKeysByCheck function

({List<String> checkedKeys, List<String> indeterminateKeys}) arcoTreeGetAllCheckedKeysByCheck(
  1. String key,
  2. bool checked,
  3. List<String> checkedKeys,
  4. ArcoTreeKeyIndex key2node,
  5. List<String> indeterminateKeys,
)

官方 getAllCheckedKeysByCheck:单次勾选后的完整勾选 / 半选集合。

Implementation

({List<String> checkedKeys, List<String> indeterminateKeys})
    arcoTreeGetAllCheckedKeysByCheck(
  String key,
  bool checked,
  List<String> checkedKeys,
  ArcoTreeKeyIndex key2node,
  List<String> indeterminateKeys,
) {
  if (!key2node.containsKey(key)) {
    return (checkedKeys: checkedKeys, indeterminateKeys: indeterminateKeys);
  }
  final Set<String> checkedKeysSet = Set<String>.of(checkedKeys);
  final Set<String> indeterminateKeysSet = Set<String>.of(indeterminateKeys);
  final Set<String> childKeys = arcoTreeCollectCheckableChildKeys(key2node[key]!, key2node);

  if (checked) {
    // 选中节点及其所有可勾选后代。
    checkedKeysSet.add(key);
    indeterminateKeysSet.remove(key);
    checkedKeysSet.addAll(childKeys);
  } else {
    indeterminateKeysSet.remove(key);
    checkedKeysSet.remove(key);
    checkedKeysSet.removeAll(childKeys);
  }

  // 之后逐级更新父节点的选中状态。
  arcoTreeUpdateParent(key, key2node, checkedKeysSet, indeterminateKeysSet);

  return (
    checkedKeys: checkedKeysSet.toList(),
    indeterminateKeys: indeterminateKeysSet.toList(),
  );
}