handleInsertItemsEvent method
Implementation
@visibleForTesting
void handleInsertItemsEvent(NodeInsertEvent<INode> event) {
if (event.index + event.items.length ==
(event.items.firstOrNull?.parent?.length ?? 0)) {
handleAddItemsEvent(NodeAddEvent(event.items));
return;
}
for (final node in event.items) {
if (animatedListStateController.containsKey(node.path)) continue;
late ITreeNode<Data> parentNode;
late int parentIndex;
if (node.isRoot || node.parent?.isRoot == true) {
parentNode = node.root as ITreeNode<Data>;
parentIndex = 0;
} else {
parentIndex = animatedListStateController.list
.indexWhere((element) => element.key == node.parent?.key);
parentNode = animatedListStateController.list[parentIndex];
}
if (parentNode.isExpanded) {
final actualIndex =
computeActualIndex(parentIndex + event.index, parentNode.level);
animatedListStateController.insertAll(
actualIndex + 1,
List.from(event.items),
);
} else {
expansionBehaviourController.expandNode(parentNode);
}
}
}