fromJson method

  1. @override
void fromJson(
  1. Map<String, dynamic> json
)
override

Deserializes JSON data into this annotation.

Implement this to update the annotation's properties from persisted data. This is called when loading saved workflows.

You typically update position, visibility, z-index, and any custom properties.

Implementation

@override
void fromJson(Map<String, dynamic> json) {
  final newPosition = Offset(
    (json['x'] as num).toDouble(),
    (json['y'] as num).toDouble(),
  );
  position = newPosition;
  visualPosition = newPosition; // Initialize visual position to match
  zIndex = json['zIndex'] as int? ?? -1;
  isVisible = json['isVisible'] as bool? ?? true;
  updateTitle(json['title'] as String? ?? '');
  updateColor(Color(json['color'] as int? ?? Colors.blue.toARGB32()));
  setSize(
    Size(
      (json['width'] as num?)?.toDouble() ?? 200.0,
      (json['height'] as num?)?.toDouble() ?? 150.0,
    ),
  );

  // Update nodeIds
  final nodeIdsList = json['nodeIds'] as List<dynamic>?;
  if (nodeIdsList != null) {
    runInAction(() {
      _nodeIds.clear();
      _nodeIds.addAll(nodeIdsList.map((e) => e as String));
    });
  }

  // Update behavior if specified
  final behaviorStr = json['behavior'] as String?;
  if (behaviorStr != null) {
    final newBehavior = GroupBehavior.values.firstWhere(
      (b) => b.name == behaviorStr,
      orElse: () => GroupBehavior.bounds,
    );
    runInAction(() => _observableBehavior.value = newBehavior);
  }
}