updateTreeMultipleChoice<T extends AbsNodeType> function
void
updateTreeMultipleChoice<T extends AbsNodeType>(})
updateTreeMultipleChoice when choose/un-choose a node:
chosenValue
: same meaning asisChosen
in AbsNodeType.isUpdatingParentRecursion
: is used to determine whether we are updating the parent/ancestors tree or updating the children of this tree.isThisLazyTree
: is this a lazy-load tree?
Implementation
void updateTreeMultipleChoice<T extends AbsNodeType>(
TreeType<T> tree,
bool? chosenValue, {
bool isUpdatingParentRecursion = false,
bool isThisLazyTree = false,
}) {
//? Step 1. update current node
tree.data.isChosen = chosenValue;
//? Step 2. update its children
if (!tree.isLeaf && !isUpdatingParentRecursion) {
/// if not [isUpdatingParentRecursion], means this is the first time call
/// function [updateTree], [chosenValue] is not nullable for now
if (chosenValue == true) {
checkAll(tree);
} else {
uncheckALl(tree);
}
}
//? Step 3. update parent
if (!tree.isRoot) {
var parent = tree.parent!;
var parentChosenValue = isChosenAll(
parent,
isThisLazyTree: isThisLazyTree,
);
switch (parentChosenValue) {
case EChosenAllValues.chosenSome:
updateTreeMultipleChoice(
parent,
null,
isUpdatingParentRecursion: true,
isThisLazyTree: isThisLazyTree,
);
break;
case EChosenAllValues.chosenAll:
updateTreeMultipleChoice(
parent,
true,
isUpdatingParentRecursion: true,
isThisLazyTree: isThisLazyTree,
);
break;
case EChosenAllValues.unchosenAll:
updateTreeMultipleChoice(
parent,
false,
isUpdatingParentRecursion: true,
isThisLazyTree: isThisLazyTree,
);
break;
default:
throw Exception("""File: tree_function.dart
Function: updateTreeMultipleChoice
Exception: EChosenAllValues.notChosenable
Message: Some logic error happen""");
}
}
}