collectHandleInit method
Collects initialization commands from widgets and state objects.
Implementation
Cmd? collectHandleInit() {
final cmds = <Cmd>[];
void visit(Element element) {
final cmd = element.widget.handleInit();
if (cmd != null) cmds.add(cmd);
// Also collect init commands from State for StatefulElements.
if (element is StatefulElement) {
final stateCmd = element.state.handleInit();
if (stateCmd != null) cmds.add(stateCmd);
}
for (final child in element.children) {
visit(child);
}
}
visit(_root);
// Drop any mount-init queue collected during startup traversal to avoid
// duplicate initialization when startup init commands are executed.
_owner.clearPendingMountInitCmds();
return cmds.isEmpty ? null : ParallelCmd(cmds);
}