From e2b873f0a57f814a3c60f20969cea22484665955 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 12 Mar 2019 10:35:08 -0700 Subject: [PATCH] Use final state passed to dart before initialization as the initial lifecycleState. (flutter/engine#8124) --- engine/src/flutter/lib/ui/hooks.dart | 5 ++++- engine/src/flutter/lib/ui/window.dart | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/lib/ui/hooks.dart b/engine/src/flutter/lib/ui/hooks.dart index 4d299c91a2..c7b18b6d34 100644 --- a/engine/src/flutter/lib/ui/hooks.dart +++ b/engine/src/flutter/lib/ui/hooks.dart @@ -92,7 +92,10 @@ void _updateUserSettingsData(String jsonData) { @pragma('vm:entry-point') // ignore: unused_element void _updateLifecycleState(String state) { - window._initialLifecycleState ??= state; + // We do not update the state if the state has already been used to initialize + // the lifecycleState. + if (!window._initialLifecycleStateAccessed) + window._initialLifecycleState = state; } diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index 6abceceb02..27a8902d2b 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/lib/ui/window.dart @@ -562,8 +562,15 @@ class Window { /// /// It is used to initialize [SchedulerBinding.lifecycleState] at startup /// with any buffered lifecycle state events. - String get initialLifecycleState => _initialLifecycleState; + String get initialLifecycleState { + _initialLifecycleStateAccessed = true; + return _initialLifecycleState; + } String _initialLifecycleState; + /// Tracks if the initial state has been accessed. Once accessed, we + /// will stop updating the [initialLifecycleState], as it is not the + /// preferred way to access the state. + bool _initialLifecycleStateAccessed = false; /// The system-reported text scale. ///