Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.4

- fix: catch flaky offstage widget finder errors in awaitImages

## 0.10.3

- fix: disable skipOffstage by default in awaitImages.
Expand Down
58 changes: 36 additions & 22 deletions lib/src/helpers/await_images.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: avoid-long-functions

import 'dart:math';

import 'package:flutter/material.dart';
Expand All @@ -11,40 +13,52 @@ extension AwaitImages on WidgetTester {
await runAsync(() async {
for (final element
in find.byType(Image, skipOffstage: false).evaluate().toList()) {
final widget = element.widget as Image;
final image = widget.image;
await precacheImage(image, element);
await pump();
try {
final widget = element.widget as Image;
final image = widget.image;
await precacheImage(image, element);
await pump();
} catch (e) {
debugPrint('An image could not be precached by awaitImages: $e');
}
}

for (final element in find
.byType(FadeInImage, skipOffstage: false)
.evaluate()
.toList()) {
final widget = element.widget as FadeInImage;
final image = widget.image;
final pumpDurationInMilliseconds = max(
widget.fadeInDuration.inMilliseconds,
widget.fadeOutDuration.inMilliseconds,
);
await precacheImage(image, element);
await pump(Duration(milliseconds: pumpDurationInMilliseconds));
try {
final widget = element.widget as FadeInImage;
final image = widget.image;
final pumpDurationInMilliseconds = max(
widget.fadeInDuration.inMilliseconds,
widget.fadeOutDuration.inMilliseconds,
);
await precacheImage(image, element);
await pump(Duration(milliseconds: pumpDurationInMilliseconds));
} catch (e) {
debugPrint('An image could not be precached by awaitImages: $e');
}
}

for (final element in find
.byType(DecoratedBox, skipOffstage: false)
.evaluate()
.toList()) {
final widget = element.widget as DecoratedBox;
final decoration = widget.decoration;
final image = switch (decoration) {
BoxDecoration() => decoration.image?.image,
ShapeDecoration() => decoration.image?.image,
_ => null,
};
if (image != null) {
await precacheImage(image, element);
await pump();
try {
final widget = element.widget as DecoratedBox;
final decoration = widget.decoration;
final image = switch (decoration) {
BoxDecoration() => decoration.image?.image,
ShapeDecoration() => decoration.image?.image,
_ => null,
};
if (image != null) {
await precacheImage(image, element);
await pump();
}
} catch (e) {
debugPrint('An image could not be precached by awaitImages: $e');
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: adaptive_test
description: >-
A Flutter package to generate adaptive golden files during widget tests.
version: 0.10.3
version: 0.10.4
homepage: https://github.com/bamlab/adaptive_test
repository: https://github.com/bamlab/adaptive_test

Expand Down
Loading