ReleaseManifest.fromJson constructor
Implementation
factory ReleaseManifest.fromJson(Map<String, Object?> json) {
var releaseStr = json['release'] as String?;
var nameStr = json['name'] as String?;
var versionStr = json['version'] as String?;
var platformStr = json['platform'] as String?;
var dateStr = json['date'] as String?;
var filesMap = json['files'] as Map<String, dynamic>;
Release release;
if (releaseStr != null) {
release = Release.parse(releaseStr);
nameStr ??= release.name;
versionStr ??= release.version.toString();
platformStr ??= release.platform;
} else {
releaseStr = '${nameStr!}/${versionStr!}';
if (platformStr != null) {
releaseStr += '/$platformStr';
}
release = Release.parse(releaseStr);
}
if (nameStr != release.name) {
throw ArgumentError('Invalid JSON. Wrong name and release.name');
}
if (versionStr != release.version.toString()) {
throw ArgumentError('Invalid JSON. Wrong version and release.version');
}
if (platformStr != release.platform) {
throw ArgumentError('Invalid JSON. Wrong platform and release.platform');
}
var date = dateStr != null ? DateTime.tryParse(dateStr) : null;
var files = filesMap.entries.map((e) => ReleaseManifestFile.fromSha256Hex(
e.key, e.value['length'], e.value['sha256']));
return ReleaseManifest(release, date: date, files: files);
}