createChildElementAfter method
MeshElement
createChildElementAfter(
- MeshElement element,
- String tagName,
- Map<
String, dynamic> attributes, { - String? id,
Implementation
MeshElement createChildElementAfter(MeshElement element, String tagName, Map<String, dynamic> attributes, {String? id}) {
final childElementType = _ensureChildValid(tagName);
_validateElementAttributes(childElementType, attributes);
if (element.parent?.id != this.id) {
throw Exception("Element does not belong to this node");
}
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": {
"after": element.id,
"children": [
{"element": elementData},
],
},
},
],
});
return getNodeByID(elementData["attributes"]!["\$id"])!;
}