Skip to content

Commit

Permalink
Skip unexpected events in MultiPlatformViewBackgroundForegroundScenar…
Browse files Browse the repository at this point in the history
…io (flutter#48456)

Fixes flutter/flutter#138193.

Was first attempted to fix in flutter#48096, but that was not reliable since it's all asynchronous. 

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
  • Loading branch information
vashworth authored and XilaiZhang committed Dec 19, 2023
1 parent 61b3360 commit beaffd7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions testing/scenario_app/lib/src/platform_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit beaffd7

Please sign in to comment.