addChild method
- String parentId,
- ElectricalNode childNode,
- Offset childPosition
Add a child node to a specific parent
Implementation
Future<void> addChild(
String parentId, ElectricalNode childNode, Offset childPosition) async {
final root = state.root;
if (root == null) return;
_saveToHistory();
try {
final newRoot = await _addChildNodeUseCase(
params: AddChildNodeParams(root, parentId, childNode));
final newPositions = Map<String, Offset>.from(state.nodePositions)
..[childNode.id] = childPosition;
emit(state.copyWith(
root: newRoot,
nodePositions: newPositions,
status: DiagramStatus.ready,
canUndo: true,
canRedo: false));
// Auto-calculate after adding nodes
validateDiagram();
} catch (e) {
emit(state.copyWith(errorMessage: "Failed to add child: $e"));
}
}