IrDocument.fromJson constructor

IrDocument.fromJson(
  1. Map<String, Object?> json
)

Implementation

factory IrDocument.fromJson(Map<String, Object?> json) {
  if (json['format'] != irFormat) {
    throw FormatException('Not a $irFormat document: ${json['format']}');
  }
  if ((json['version'] as num? ?? 0) > irVersion) {
    throw FormatException(
      'IR version ${json['version']} is newer than $irVersion',
    );
  }
  return IrDocument(
    project: json['project'] as String,
    screens: [
      for (final s in json['screens'] as List)
        IrScreen.fromJson(s as Map<String, Object?>),
    ],
    designSystem: json['designSystem'] == null
        ? null
        : IrDesignSystem.fromJson(
            json['designSystem'] as Map<String, Object?>,
          ),
    diagnostics: [
      for (final d in (json['diagnostics'] as List? ?? const []))
        IrDiagnostic.fromJson(d as Map<String, Object?>),
    ],
    images: {
      for (final MapEntry(:key, :value)
          in ((json['images'] as Map?) ?? const {}).entries)
        key as String: IrImageAsset.fromJson(
          key,
          value as Map<String, Object?>,
        ),
    },
  );
}