parseMap method

ParsedUi parseMap(
  1. Map<String, dynamic> json
)

Parse from a decoded map. Throws JsonParserException on invalid structure. When schemaVersion is present, it must be in supportedVersions.

Implementation

ParsedUi parseMap(Map<String, dynamic> json) {
  String? schemaVersion = json['schemaVersion'] as String?;
  if (schemaVersion != null &&
      schemaVersion.isNotEmpty &&
      !supportedVersions.contains(schemaVersion)) {
    throw JsonParserException(
      'Unsupported schemaVersion: "$schemaVersion". Supported: $supportedVersions',
    );
  }

  final rootMap = json['ui'] as Map<String, dynamic>? ?? json;

  WidgetDescriptor root = _parseNode(rootMap);
  return ParsedUi(schemaVersion: schemaVersion, root: root);
}