createChild method
Creates or updates the child for the given node.
Implementation
@override
void createChild(TKey nodeId) {
assert(_inLayout, 'createChild must be called during layout');
final existing = _children[nodeId];
// Three cases handled here:
// 1. No existing element: build a fresh widget via [nodeBuilder].
// 2. Existing element, queued as dirty by a prior update / notify:
// rebuild with a fresh widget so the row picks up any new state
// captured by the `nodeBuilder` closure or new controller data.
// 3. Existing element, not dirty: no-op — this is the hot path
// every layout hits for already-mounted cache-region keys.
final needsRefresh = existing != null && _dirtyKeys.remove(nodeId);
if (existing != null && !needsRefresh) {
return;
}
owner!.buildScope(this, () {
final nodeData = widget.controller.getNodeData(nodeId);
if (nodeData == null) {
return;
}
final depth = widget.controller.getDepth(nodeId);
final childWidget = widget.nodeBuilder(this, nodeId, depth);
final element = updateChild(existing, childWidget, nodeId);
if (element != null) {
_children[nodeId] = element;
} else if (existing != null) {
_children.remove(nodeId);
}
});
}