render method
Render the DOM element and add it to the context.
Implementation
Element render(BuildContext context) {
final childElement = context.child?.element;
if (context.child == null || childElement == null) {
window.console.warn("Snap... we hit a render issue");
window.console.warn("Widget parent: ${context.parent?.widget}");
window.console.warn("Widget: ${context.widget}");
window.console.warn("Widget child: ${context.child?.widget}");
window.console.warn("Element parent: ${context.parent?.element}");
window.console.warn("Element: ${context.element}");
window.console.warn("Element child: ${context.child?.element}");
}
if (context.child == null) {
throw Exception("This element has no child");
} else if (childElement == null) {
throw Exception("This elment was not rendered");
}
var newElement = childElement;
if (newElement.hasAttribute(_dataWidgetTypeKey) ||
newElement.hasAttribute(_dataWidgetTypeId)) {
if (newElement.getAttribute(_dataWidgetTypeId) != hashCode.toString()) {
newElement = SpanElement()..children = [newElement];
}
}
newElement
..setAttribute(_dataWidgetTypeKey, runtimeType.toString())
..setAttribute(_dataWidgetTypeId, hashCode.toString());
if (context.element != null && context.element?.parentNode != null) {
context.element!.replaceWith(newElement);
}
context.element = newElement;
return context.element!;
}