From 13cdf933d64195715e46535866bded85c1c1fe3f Mon Sep 17 00:00:00 2001 From: Victoria Ashworth <15619084+vashworth@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:02:57 -0600 Subject: [PATCH] Fix race condition in Unobstructed Platform View Scenario tests (#48096) Fixes race situation where `_onPlatformMessage` is triggered before the first frame, essentially skipping the first frame. Fixes https://github.com/flutter/flutter/issues/138193. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- testing/scenario_app/lib/src/platform_view.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/testing/scenario_app/lib/src/platform_view.dart b/testing/scenario_app/lib/src/platform_view.dart index 39e6d42c16c97..d232546f76dcd 100644 --- a/testing/scenario_app/lib/src/platform_view.dart +++ b/testing/scenario_app/lib/src/platform_view.dart @@ -422,7 +422,6 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario required this.secondId, }) { _nextFrame = _firstFrame; - channelBuffers.setListener('flutter/lifecycle', _onPlatformMessage); } /// The platform view identifier to use for the first platform view. @@ -438,7 +437,13 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario _nextFrame(); } + bool _firstFrameBegan = false; + void _firstFrame() { + if (!_firstFrameBegan) { + channelBuffers.setListener('flutter/lifecycle', _onPlatformMessage); + } + _firstFrameBegan = true; final SceneBuilder builder = SceneBuilder(); builder.pushOffset(50, 600);