generateWithRoot method

T? generateWithRoot(
  1. DOMElement? domRoot,
  2. T? rootElement,
  3. List<DOMNode> nodes, {
  4. DOMTreeMap<T>? treeMap,
  5. T? rootParent,
  6. DOMContext<T>? context,
  7. bool finalizeTree = true,
  8. bool setTreeMapRoot = true,
})

Same as generate, but generates nodes inside a preexistent rootElement.

Implementation

T? generateWithRoot(DOMElement? domRoot, T? rootElement, List<DOMNode> nodes,
    {DOMTreeMap<T>? treeMap,
    T? rootParent,
    DOMContext<T>? context,
    bool finalizeTree = true,
    bool setTreeMapRoot = true}) {
  treeMap ??= createGenericDOMTreeMap();
  context ??= _domContext;

  if (rootElement == null && domRoot != null) {
    rootElement = treeMap.getMappedElement(domRoot);
    rootElement ??= build(null, null, domRoot, treeMap, context);
  }

  if (rootElement == null) throw StateError("Null `rootElement`.");

  domRoot ??= treeMap.getMappedDOMNode(rootElement) as DOMElement?;

  if (rootParent != null) {
    addChildToElement(rootParent, rootElement);
  }

  treeMap.map(domRoot!, rootElement);

  for (var node in nodes) {
    if (!domRoot.containsNode(node)) {
      domRoot.add(node);
    }
    build(domRoot, rootElement, node, treeMap, context);
  }

  if (setTreeMapRoot) {
    treeMap.setRoot(domRoot, rootElement);
  }

  _callFinalizeGeneratedTree(treeMap, context, finalizeTree);

  return rootElement;
}