dvPrefetchImages function
List<String>
dvPrefetchImages(
- String? manifest,
- String path, {
- DVImageVariants? variants,
- double devicePixelRatio = 1,
The images the build recorded path painting on load, or none.
An image drawn through a variant is recorded with the slot it was laid
out in, and fetched at the variant for devicePixelRatio -- this screen's,
not the build's -- through the same DVImageVariants.variantUrl the
widget uses, so the link fetches the file the page will ask for. Where
there is no variant for it, the image itself, as the widget would.
Never throws. A missing, stale or mangled manifest is a site without image prefetch, not a link that fails on the way to a tap.
Implementation
List<String> dvPrefetchImages(
String? manifest,
String path, {
DVImageVariants? variants,
double devicePixelRatio = 1,
}) {
if (manifest == null || manifest.isEmpty) return const <String>[];
final Object? json;
try {
json = jsonDecode(manifest);
} on FormatException {
return const <String>[];
}
if (json is! Map) return const <String>[];
final Object? routes = json['routes'];
if (routes is! Map) return const <String>[];
final Object? route = routes[_routeKey(path)];
if (route is! Map) return const <String>[];
final Object? images = route['images'];
if (images is! List) return const <String>[];
return <String>[
for (final Object? image in images)
if (image case {'url': final String url} when url.isNotEmpty)
_forThisScreen(image, url, variants, devicePixelRatio),
];
}