buildElement method

T buildElement(
  1. DOMElement? domParent,
  2. T? parent,
  3. DOMElement domElement,
  4. DOMTreeMap<T> treeMap,
  5. DOMContext<T>? context,
)

Implementation

T buildElement(DOMElement? domParent, T? parent, DOMElement domElement,
    DOMTreeMap<T> treeMap, DOMContext<T>? context) {
  if (domParent != null) {
    domElement.parent = domParent;
  }

  var element = createWithRegisteredElementGenerator(
      domParent, parent, domElement, treeMap, context);

  if (element == null) {
    if (_domContext != null) {
      element = _domContext!
          .resolveNamedElement(domParent, parent, domElement, treeMap);
      element ??= createElement(domElement.tag, domElement);
    } else {
      element = createElement(domElement.tag, domElement);
    }

    if (element == null) {
      throw StateError("Can't create element for tag: ${domElement.tag}");
    }

    if (parent != null) {
      addChildToElement(parent, element);
    }

    treeMap.map(domElement, element);
    _callOnElementCreated(treeMap, domElement, element, context);

    setAttributes(domElement, element, treeMap,
        preserveClass: true, preserveStyle: true);

    var length = domElement.length;

    for (var i = 0; i < length; i++) {
      var node = domElement.nodeByIndex(i)!;
      build(domElement, element, node, treeMap, context);
    }
  } else if (parent != null) {
    addChildToElement(parent, element);
  }

  domElement.notifyElementGenerated(element);

  return element;
}