From 9d8970f5ec61effde1bc27896045d219a139072f Mon Sep 17 00:00:00 2001 From: MaximeRougieux Date: Tue, 2 Jun 2026 10:54:59 +0200 Subject: [PATCH 1/2] fix: :bug: flaky widget finder after skipOffstage: false update --- lib/src/helpers/await_images.dart | 58 +++++++++++++++++++------------ 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/lib/src/helpers/await_images.dart b/lib/src/helpers/await_images.dart index 783f1cb..8cfdcda 100644 --- a/lib/src/helpers/await_images.dart +++ b/lib/src/helpers/await_images.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid-long-functions + import 'dart:math'; import 'package:flutter/material.dart'; @@ -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'); } } }); From a0fe1f7c9f0479262777dcbc4f77a49a9ed20679 Mon Sep 17 00:00:00 2001 From: MaximeRougieux Date: Tue, 2 Jun 2026 10:56:38 +0200 Subject: [PATCH 2/2] chore: :bookmark: bump package to 0.10.4 --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04b4103..4a56c17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/pubspec.yaml b/pubspec.yaml index 15518ff..6fca261 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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