fromJson static method

dynamic fromJson(
  1. String widgetType,
  2. Map<String, dynamic> json
)

fromJson method

Implementation

static fromJson(String widgetType, Map<String, dynamic> json) {
  if (widgetType != NType.spacer) {
    throw Exception('Invalid widget type');
  }

  final attributes = <String, dynamic>{};
  if (json['properties'] != null) {
    for (final entry in (json['properties'] as Map<String, dynamic>)
        .entries
        .where((e) => e.value != null)) {
      attributes[entry.key] =
          const DynamicAttributes().fromJson(entry.key, entry.value);
    }
  }

  final rectProperties = RectProperties.fromJson(json['rect_properties']);

  return SpacerOpenNode(
    id: json['id'],
    name: json['name'],
    description: json['description'],
    parentID: json['parent_id'],
    attributes: attributes,
    rectProperties: rectProperties,
    updatedAt: DateTime.parse(json['updated_at']),
    childOrder: json['child_order'] != null
        ? (json['child_order'] as num).toDouble()
        : null,
    pageID: json['page_id'],
    stabilID: json['stabil_id'],
    componentID: json['component_id'],
    isLocked: json['is_locked'],
  );
}