rebuild method
Re-derives this node by running build again over the wreckage of the last one.
Everything the previous build made is thrown away:
- All added direct children are removed.
- All tick, draw, and debugDraw closures are removed.
- The trash is processed and cleared.
Then, build runs again from the top, so constructor arguments are re-evaluated exactly like a statement is. What survives is this node itself: its members, its position, and anything added to it imperatively.
A child the new body adds back is preserved rather than replaced, which makes a child held on the instance a boundary this rebuild stops at.
Call this inside reassemble when your node knows how to reboot itself directly from its instance members to witness true live reload.
Implementation
@nonVirtual
void rebuild() {
_discardDeclared();
// Dropped rather than cleared, so a rebuild from inside an [onUpdate]
// leaves the list that call is being iterated from intact. Its remaining
// closures run out the frame; the new build installs its own for the next.
_ticks = null;
_draws = null;
_debugDraws = null;
_cleanup();
final builder = _builder;
_builder = this;
try {
build();
final scene = _scene;
if (scene != null && scene.hasSize) {
onSceneResize.emit(scene.size);
}
} finally {
_builder = builder;
}
}