readInitialLifecycleStateFromNativeWindow method Null safety

  1. @protected
void readInitialLifecycleStateFromNativeWindow()

Initializes the lifecycleState with the dart:ui.SingletonFlutterWindow.initialLifecycleState.

Once the lifecycleState is populated through any means (including this method), this method will do nothing. This is because the dart:ui.SingletonFlutterWindow.initialLifecycleState may already be stale and it no longer makes sense to use the initial state at dart vm startup as the current state anymore.

The latest state should be obtained by subscribing to WidgetsBindingObserver.didChangeAppLifecycleState.

Implementation

@protected
void readInitialLifecycleStateFromNativeWindow() {
  if (lifecycleState != null) {
    return;
  }
  final AppLifecycleState? state = _parseAppLifecycleMessage(window.initialLifecycleState);
  if (state != null) {
    handleAppLifecycleStateChanged(state);
  }
}