clear method
Clears the component, removing the last rendered content.
- If
forceistrueperforms a clear operation even if isRendered returnsfalse. - If
removeFromParentistrueit will also remove the content element from the parent.
Implementation
void clear({bool force = false, bool removeFromParent = false}) {
if (!force && !isRendered) return;
if (!force && preserveRender) {
// When any UIAsyncContent is loading, it relies on the previously
// rendered elements to attach the newly loaded content, replacing
// the old nodes. Clearing the component elements here would break
// that attachment process.
if (isLoadingUIAsyncContent) {
return;
}
}
if (_renderedElements != null) {
for (var e in _renderedElements!) {
if (e is UIComponent) {
e.delete();
} else if (e.isElement) {
(e as Element).remove();
}
}
_renderedElements = null;
}
_renderedAsyncContents?.clear();
_renderedAsyncContents = null;
var content = _content;
if (content != null) {
// Removes all the child nodes at once (`innerHTML = ''`):
content.clear();
if (removeFromParent) {
content.remove();
}
}
_rendered = false;
}