@@ -179,6 +179,10 @@ void main() {
179
179
return completer1;
180
180
})! as TestImageStreamCompleter ;
181
181
182
+ // Make the image seem live.
183
+ final ImageStreamListener listener = ImageStreamListener ((_, __) {});
184
+ completer1.addListener (listener);
185
+
182
186
expect (imageCache.statusForKey (testImage).pending, true );
183
187
expect (imageCache.statusForKey (testImage).live, true );
184
188
imageCache.clear ();
@@ -346,10 +350,10 @@ void main() {
346
350
347
351
imageCache.clear ();
348
352
expect (imageCache.statusForKey (testImage1).pending, false );
349
- expect (imageCache.statusForKey (testImage1).live, true );
353
+ expect (imageCache.statusForKey (testImage1).live, false );
350
354
351
355
completer1.testSetImage (testImage1);
352
- expect (imageCache.statusForKey (testImage1).keepAlive, true );
356
+ expect (imageCache.statusForKey (testImage1).keepAlive, false );
353
357
expect (imageCache.statusForKey (testImage1).live, false );
354
358
355
359
imageCache.putIfAbsent (testImage2, () => completer2);
@@ -602,4 +606,27 @@ void main() {
602
606
imageInfo.dispose ();
603
607
expect (testImage.debugGetOpenHandleStackTraces ()! .length, 0 );
604
608
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/87442
609
+
610
+ test ('clear does not leave pending images stuck' , () async {
611
+ final ui.Image testImage = await createTestImage (width: 8 , height: 8 );
612
+
613
+ final TestImageStreamCompleter completer1 = TestImageStreamCompleter ();
614
+
615
+ imageCache.putIfAbsent (testImage, () {
616
+ return completer1;
617
+ });
618
+
619
+ expect (imageCache.statusForKey (testImage).pending, true );
620
+ expect (imageCache.statusForKey (testImage).live, true );
621
+ expect (imageCache.statusForKey (testImage).keepAlive, false );
622
+
623
+ imageCache.clear ();
624
+
625
+ // No one else is listening to the completer. It should not be considered
626
+ // live anymore.
627
+
628
+ expect (imageCache.statusForKey (testImage).pending, false );
629
+ expect (imageCache.statusForKey (testImage).live, false );
630
+ expect (imageCache.statusForKey (testImage).keepAlive, false );
631
+ });
605
632
}
0 commit comments