GroupNode<T>.fromJson constructor
Creates a GroupNode from a JSON map.
This factory constructor is used during workflow deserialization to recreate group nodes from saved data.
Parameters:
json- The JSON map containing node datadataFromJson- Function to deserialize the custom data of typeT
Implementation
factory GroupNode.fromJson(
Map<String, dynamic> json, {
required T Function(Object? json) dataFromJson,
}) {
// Parse padding from JSON (stored as LTRB array or object)
EdgeInsets padding = kGroupNodeDefaultPadding;
final paddingJson = json['padding'];
if (paddingJson != null) {
if (paddingJson is List) {
padding = EdgeInsets.fromLTRB(
(paddingJson[0] as num).toDouble(),
(paddingJson[1] as num).toDouble(),
(paddingJson[2] as num).toDouble(),
(paddingJson[3] as num).toDouble(),
);
} else if (paddingJson is Map) {
padding = EdgeInsets.fromLTRB(
(paddingJson['left'] as num?)?.toDouble() ?? 0,
(paddingJson['top'] as num?)?.toDouble() ?? 0,
(paddingJson['right'] as num?)?.toDouble() ?? 0,
(paddingJson['bottom'] as num?)?.toDouble() ?? 0,
);
}
}
// Parse ports
final inputPorts =
(json['inputPorts'] as List<dynamic>?)
?.map((e) => Port.fromJson(Map<String, dynamic>.from(e as Map)))
.toList() ??
const [];
final outputPorts =
(json['outputPorts'] as List<dynamic>?)
?.map((e) => Port.fromJson(Map<String, dynamic>.from(e as Map)))
.toList() ??
const [];
return GroupNode<T>(
id: json['id'] as String,
position: Offset(
(json['x'] as num).toDouble(),
(json['y'] as num).toDouble(),
),
size: Size(
(json['width'] as num?)?.toDouble() ?? 200.0,
(json['height'] as num?)?.toDouble() ?? 150.0,
),
title: json['title'] as String? ?? '',
data: dataFromJson(json['data']),
color: Color(json['color'] as int? ?? Colors.blue.toARGB32()),
behavior: GroupBehavior.values.byName(
json['behavior'] as String? ?? 'bounds',
),
nodeIds: (json['nodeIds'] as List<dynamic>?)
?.map((e) => e as String)
.toSet(),
padding: padding,
zIndex: json['zIndex'] as int? ?? -1,
isVisible: json['isVisible'] as bool? ?? true,
locked: json['locked'] as bool? ?? false,
inputPorts: inputPorts,
outputPorts: outputPorts,
);
}