inflate method
Set this widget context, build it’s child, and render the widget, updating
Context.element
When overriding pay attention that inflate need to call
build
and render
Implementation
@override
void inflate(BuildContext context) {
context.widget = this;
final oldDomElements = context.domChildren ?? [];
context.domChildren = [];
final wasChildUsed = List.filled(oldDomElements.length, false);
// context propagation to children
if (children != null) {
for (var i = 0; i < children!.length; i++) {
final child = children![i];
/// Try to find if we already have this widget in the dom
var sameHashCodePos = -1;
var sameRunTypePos = -1;
for (var i = 0; i < oldDomElements.length; i++) {
final context = oldDomElements[i];
if (context.widget.hashCode == child.hashCode &&
context.widget?.key == child.key &&
!wasChildUsed[i]) {
sameHashCodePos = i;
break;
}
if (context.widget.runtimeType == child.runtimeType &&
context.widget?.key == child.key &&
!wasChildUsed[i] &&
sameRunTypePos == -1) {
sameRunTypePos = i;
}
}
/// Was the element already created ?
if (sameHashCodePos != -1 &&
oldDomElements[i].element?.isConnected == true) {
context.domChildren!.add(oldDomElements[i]);
oldDomElements[i].parent = context;
assert(oldDomElements[i].element?.isConnected == true);
wasChildUsed[sameHashCodePos] = true;
} else {
BuildContext? target;
if (sameRunTypePos != -1) {
wasChildUsed[sameRunTypePos] = true;
target = oldDomElements[sameRunTypePos];
}
final childContext = context.createChildContext(
copyOldProperties: target != null, target: target);
context.domChildren!.add(childContext);
child.inflate(childContext);
}
}
}
render(context);
}