From 3f3e560236539b7e2702f5ac790b2a4691b32d49 Mon Sep 17 00:00:00 2001 From: Xilai Zhang Date: Tue, 19 Dec 2023 12:48:00 -0800 Subject: [PATCH] =?UTF-8?q?[cherrypick-stable]Skip=20unexpected=20events?= =?UTF-8?q?=20in=20MultiPlatformViewBackgroundForegroundScenar=E2=80=A6=20?= =?UTF-8?q?(#49247)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …io (#48456) Fixes https://github.com/flutter/flutter/issues/138193. Was first attempted to fix in https://github.com/flutter/engine/pull/48096, but that was not reliable since it's all asynchronous. ------------------------------------------- cherry pick to fix mac unopt failures on stable branch: https://flutter-dashboard.appspot.com/#/build?repo=engine&branch=flutter-3.16-candidate.0 --- testing/scenario_app/lib/src/platform_view.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testing/scenario_app/lib/src/platform_view.dart b/testing/scenario_app/lib/src/platform_view.dart index 7c15465dc9ea8..92679d2a94ae1 100644 --- a/testing/scenario_app/lib/src/platform_view.dart +++ b/testing/scenario_app/lib/src/platform_view.dart @@ -510,6 +510,13 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario PlatformMessageResponseCallback? callback, ) { final String message = utf8.decode(data!.buffer.asUint8List()); + + // The expected first event should be 'AppLifecycleState.resumed', but + // occasionally it will receive 'AppLifecycleState.inactive' first. Skip + // any messages until 'AppLifecycleState.resumed' is received. + if (_lastLifecycleState.isEmpty && message != 'AppLifecycleState.resumed') { + return; + } if (_lastLifecycleState == 'AppLifecycleState.inactive' && message == 'AppLifecycleState.resumed') { _nextFrame = _secondFrame;