From 30cce4dcd24a28c910cc96f56756921a5d62d8f6 Mon Sep 17 00:00:00 2001 From: Nate Biggs Date: Wed, 24 Jul 2024 21:23:05 -0400 Subject: [PATCH] Update fake_codec.dart to use Future.value instead of SynchronousFuture (#152182) Upcoming changes to DDC change the async semantics of code produced by the compiler. The changes will bring the semantics more in line with those of dart2js and fix several bugs in the old semantics. However in landing those changes I experienced a test failure in [obscured_animated_image_test](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/obscured_animated_image_test.dart). Some debugging uncovered that this is due to the use of `SynchronousFuture` in this `FakeCodec`. The old DDC async semantics forced an async gap when that future was [awaited](https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/painting/image_stream.dart#L1064). The new async semantics do not create an async gap here. This changes the render ordering of the widget tree created in the test leading to the test failure. `Future.value` should be a reasonable substitute here and should achieve what the test was trying to achieve while also preserving the correct render ordering given the new DDC semantics. --- packages/flutter/test/painting/fake_codec.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/flutter/test/painting/fake_codec.dart b/packages/flutter/test/painting/fake_codec.dart index 1a7757f14a..060ee1ab26 100644 --- a/packages/flutter/test/painting/fake_codec.dart +++ b/packages/flutter/test/painting/fake_codec.dart @@ -44,8 +44,8 @@ class FakeCodec implements ui.Codec { @override Future getNextFrame() { _numFramesAsked += 1; - final SynchronousFuture result = - SynchronousFuture(_frameInfos[_nextFrame]); + final Future result = + Future.value(_frameInfos[_nextFrame]); _nextFrame = (_nextFrame + 1) % _frameCount; return result; }