searchLeavesWithTitleDFS<T extends AbsNodeType> function

void searchLeavesWithTitleDFS<T extends AbsNodeType>(
  1. TreeType<T> tree,
  2. String text,
  3. List<TreeType<T>> result
)

Using DFS to return leaves if each of leaf's data contains searching text

Implementation

void searchLeavesWithTitleDFS<T extends AbsNodeType>(
    TreeType<T> tree, String text, List<TreeType<T>> result) {
  if (tree.data.isUnavailable) return;

  if (tree.isLeaf && tree.data.title.contains(text)) {
    result.add(tree);
    return;
  }

  for (var child in tree.children) {
    searchAllTreesWithTitleDFS(child, text, result);
  }
}