Commit 71048065 authored by Harry Terkelsen's avatar Harry Terkelsen Committed by Jonah Williams

Fix bug in FadeInImage causing changes in placeholder to be missed (#20356)

parent b7a6c169
......@@ -393,7 +393,7 @@ class _FadeInImageState extends State<FadeInImage> with TickerProviderStateMixin
@override
void didUpdateWidget(FadeInImage oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.image != oldWidget.image || widget.placeholder != widget.placeholder)
if (widget.image != oldWidget.image || widget.placeholder != oldWidget.placeholder)
_resolveImage();
}
......
......@@ -13,6 +13,7 @@ Future<Null> main() async {
// These must run outside test zone to complete
final ui.Image targetImage = await createTestImage();
final ui.Image placeholderImage = await createTestImage();
final ui.Image secondPlaceholderImage = await createTestImage();
group('FadeInImage', () {
testWidgets('animates uncached image and shows cached image immediately', (WidgetTester tester) async {
......@@ -80,5 +81,40 @@ Future<Null> main() async {
expect(stateAfterRecreate.phase, FadeInImagePhase.completed); // completes immediately
expect(displayedImage().image, same(targetImage));
});
testWidgets('handles a updating the placeholder image', (WidgetTester tester) async {
RawImage displayedImage() => tester.widget(find.byType(RawImage));
// The placeholder is expected to be already loaded
final TestImageProvider placeholderProvider = new TestImageProvider(placeholderImage);
final TestImageProvider secondPlaceholderProvider = new TestImageProvider(secondPlaceholderImage);
// Test case: long loading image
final TestImageProvider imageProvider = new TestImageProvider(targetImage);
await tester.pumpWidget(new FadeInImage(
placeholder: placeholderProvider,
image: imageProvider,
fadeOutDuration: const Duration(milliseconds: 50),
fadeInDuration: const Duration(milliseconds: 50),
));
placeholderProvider.complete();
await tester.pump();
expect(displayedImage().image, same(placeholderImage)); // placeholder completed
expect(displayedImage().image, isNot(same(secondPlaceholderImage)));
await tester.pumpWidget(new FadeInImage(
placeholder: secondPlaceholderProvider,
image: imageProvider,
fadeOutDuration: const Duration(milliseconds: 50),
fadeInDuration: const Duration(milliseconds: 50),
));
secondPlaceholderProvider.complete();
await tester.pump();
expect(displayedImage().image, isNot(same(placeholderImage))); // placeholder replaced
expect(displayedImage().image, same(secondPlaceholderImage));
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment