fromJson static method
Parses toJson output; null for entries this build cannot reproduce (unknown family or hero, a family the recipe's version never shipped, newer engine version).
Implementation
static FeedEntry? fromJson(Object? json) {
if (json is! Map) return null;
final kind = json['kind'];
if (kind == 'hero') {
final id = json['heroId'];
if (id is! int || heroById(id) == null) return null;
return FeedEntry.hero(id);
}
if (kind == 'generated') {
final seed = json['seed'];
final familyId = json['family'];
final version = json['engineVersion'];
if (seed is! int || familyId is! int || version is! int) return null;
final family = ThemeFamily.fromId(familyId);
if (family == null || family == ThemeFamily.plain) return null;
if (!supportedEngineVersions.contains(version)) return null;
// A recipe for a family that version never shipped cannot be
// reproduced (placeholder definitions change when it ships).
if (!familyShippedAt(family, version)) return null;
final rawIntent = json['intent'];
final intent = rawIntent == null
? null
: ThemeIntent.fromJson(rawIntent).forEntry;
if (intent != null && version < firstSteerableEngineVersion) {
return null;
}
return FeedEntry.generated(
seed: seed & 0xFFFFFFFF,
family: family,
engineVersion: version,
intent: intent == null || intent.isEmpty ? null : intent,
centred: intent != null && json['centred'] == true,
);
}
return null;
}