NodeModel<T> constructor

NodeModel<T>({
  1. Vector2? position,
  2. String? id,
  3. T? data,
  4. List<NodeSocketModel>? inputSockets,
  5. List<NodeSocketModel>? outputSockets,
})

Implementation

NodeModel({
  Vector2? position,
  String? id,
  this.data,
  List<NodeSocketModel>? inputSockets,
  List<NodeSocketModel>? outputSockets,
}) {
  this.id = id ?? UniqueKey().toString();
  this.key = GlobalKey();
  this.position = position ?? Vector2.zero;
  this.inputSockets = inputSockets ?? [];
  this.outputSockets = outputSockets ?? [];
  if (this.inputSockets.isEmpty && this.outputSockets.isEmpty) {
    this.inputSockets.addAll([
      NodeSocketModel(
        nodeId: this.id,
        id: UniqueKey().toString(),
        type: NodeSocketType.input,
        position: Vector2.zero,
        data: {},
      ),
    ]);
    this.outputSockets.addAll([
      NodeSocketModel(
        nodeId: this.id,
        id: UniqueKey().toString(),
        type: NodeSocketType.output,
        position: Vector2.zero,
        data: {},
      ),
    ]);
  }
}