childrenProvider property

ChildrenProvider<T> childrenProvider
final

A callback used when building the flat representation of the tree to get the direct children of the tree node passed to it.

Avoid doing heavy computations in this callback since it is going to be called a lot when traversing the tree.

Example using nested objects:

class Node {
  List<Node> children;
}

Iterable<Node> childrenProvider(Node node) => node.children;

Example using a Map cache:

class Data {
  final int id;
}

final Map<int, List<Data>> childrenCache = <int, List<Data>>{};

Iterable<Data> childrenProvider(Data parent) {
  return childrenCache[parent.id] ?? const Iterable.empty();
},

Do not attempt to load the children of a node in this callback as it would significantly slow down tree traversal which might cause the ui to hang. Prefer doing such operations on a user interaction (e.g., a button press, keyboard shortcut, etc.). When lazy loading, temporarily return an empty iterable so tree traversal can continue. Once the loading is done, set the expansion state of the parent node to true and call rebuild to reveal the loaded nodes.

Implementation

final ChildrenProvider<T> childrenProvider;