decodeBlock function
Rebuilds one Block from json and the images its references name.
Returns null on unreadable json, a schema-version mismatch, or an
unresolved image reference, exactly like decodeBookDocument.
Unlike decodeBookDocument, a lone block carries no metadata to seed the
default segmenter from, so with segmenter omitted a paragraph gets the
unseeded default. A consumer restoring blocks of a non-Latin book
supplies RuleBasedSegmenter(languageCode: ...) itself.
Implementation
Block? decodeBlock(
Map<String, dynamic> json, {
Map<String, ImageData> images = const {},
TextSegmenter? segmenter,
}) {
try {
if (json['v'] != kBookDocumentSchemaVersion) return null;
return _blockFromJson(
json,
images,
segmenter ?? const RuleBasedSegmenter(),
);
} catch (_) {
return null;
}
}