populateFromList method Null safety

void populateFromList(
  1. List<T> elements,
  2. T getParent(
    1. T child
    )
)

Implementation

void populateFromList(List<T> elements, T Function(T child) getParent) {
  for (var element in elements) {
    var parent = getParent(element);
    if (parent == null) {
      root!.addChild(element);
    } else {
      _addChildToParent(element, parent, getParent);
    }
  }
}