defaultPrimeAssets function
A function that waits for all Image widgets found in the widget tree to finish decoding.
Currently this supports images included via Image widgets, or as part of BoxDecorations.
See also:
- GoldenToolkitConfiguration.primeAssets to configure a global asset prime function.
Implementation
Future<void> defaultPrimeAssets(WidgetTester tester) async {
final imageElements = find.byType(Image, skipOffstage: false).evaluate();
final containerElements =
find.byType(DecoratedBox, skipOffstage: false).evaluate();
await tester.runAsync(() async {
for (final imageElement in imageElements) {
final widget = imageElement.widget;
if (widget is Image) {
await precacheImage(widget.image, imageElement);
}
}
for (final container in containerElements) {
final widget = container.widget as DecoratedBox;
final decoration = widget.decoration;
if (decoration is BoxDecoration) {
if (decoration.image != null) {
await precacheImage(decoration.image!.image, container);
}
}
}
});
}