performLayout method
Override this method to lay out and position all children given this widget's size.
This method must call layoutChild for each child. It should also specify the final position of each child with positionChild.
Implementation
@override
void performLayout(Size size) {
// Layout each node at its position
for (final node in nodes) {
if (hasChild(node.id)) {
final currentPosition = node.position.value;
final previousPosition = _previousPositions[node.id];
// Layout the child with loose constraints
layoutChild(node.id, BoxConstraints.loose(size));
// Only position child if it has moved or is new
if (previousPosition != currentPosition) {
positionChild(node.id, currentPosition);
_previousPositions[node.id] = currentPosition;
}
}
}
// Clean up positions for removed nodes
_previousPositions.removeWhere(
(id, _) => !nodes.any((node) => node.id == id),
);
}