precacheImages function
Pre-caches all images so that they will be rendered correctly when taking screenshots.
An optional Finder can be provided to limit the scope of the precaching to matching descendants of that Finder.
Implementation
Future<void> precacheImages([Finder? from]) async {
final finder = from ?? find.byType(View);
await maybeRunAsync(() async {
final children = find.descendant(
of: finder,
matching: find.bySubtype<Image>(),
);
final operations = children.evaluate().map((e) {
final image = e.widget as Image;
return precacheImage(image.image, e);
});
return Future.wait(operations);
});
}