toTree<D, T extends TreeNode<T> > function
T
toTree<D, T extends TreeNode<T> >(})
Implementation
T toTree<D, T extends TreeNode<T>>(
D data,
List<D> Function(D) childrenCallback,
T Function(T?, D) build, {
int deep = 0,
T? parent,
int Function(T, T)? sort,
}) {
T root = build.call(parent, data);
root._deep = deep;
root.parent = parent;
for (var child in childrenCallback.call(data)) {
root.add(toTree<D, T>(child, childrenCallback, build, deep: deep + 1, parent: root));
}
if (sort != null) {
root._childrenList.sort((a, b) {
return sort.call(a, b);
});
}
return root;
}