This is no definitive answer, and I'd be happy if someone could provide further info, but as far as I can tell there is no callback to check this.
The following is tested with an app where iOS triggers prewarming upon receival of a push notification - either with locked or unlocked screen.
When adding a WidgetsBindingObserver
first things first in the main() function, this observer's didChangeAppLifecycleState
fires with AppLifecycleState.inactive
when prewarming begins (independently of whether the screen is locked or not when prewarming). But it does the same on a normal app start, except then soon after a resumed
state is received as well.
It seems that some things can interrupt prewarming, like a await Future.delayed(Duration(seconds: 2));
or a runApp(SomePointlessWidget());
.
Also note that when depending on the Keychain in your initializations, contents can be unavailable (when prewarming is triggered while the screen is locked) and you could, for example, check by writing and reading a dummy variable whether the Keychain is available. Because callbacks like applicationProtectedDataDidBecomeAvailable:
seem to be unavailable in flutter, cf. this PR: https://github.com/flutter/flutter/pull/9818 (see also https://github.com/flutter/flutter/issues/9682).