createChildElement method

MeshElement createChildElement(
  1. String tagName,
  2. Map<String, dynamic> attributes, {
  3. String? id,
})

Implementation

MeshElement createChildElement(String tagName, Map<String, dynamic> attributes, {String? id}) {
  final childElementType = _ensureChildValid(tagName);
  _validateElementAttributes(childElementType, attributes);
  final elementData = <String, dynamic>{
    "name": tagName,
    "attributes": {"\$id": id ?? const Uuid().v4(), ...attributes},
    "children": _defaultChildren(tagName),
  };
  doc.sendChanges({
    "documentID": doc.id,
    "changes": [
      {
        "nodeID": this.id,
        "insertChildren": {
          "children": [
            {"element": elementData},
          ],
        },
      },
    ],
  });
  return getNodeByID(elementData["attributes"]["\$id"])!;
}