dvAppLifecycleFor function
What state means for DV.lifecycle.app, or null when it means nothing.
Separate from the observer so the judgement can be tested without a binding, and so the two cannot drift.
Implementation
DVAppLifecycle? dvAppLifecycleFor(AppLifecycleState state) {
switch (state) {
// Both are the background. Flutter sends hidden before paused on every
// platform now, and on desktop it is the whole of it: a window that is
// covered or minimised never reaches paused, so an application that
// listened only for paused would save nothing on a desktop.
case AppLifecycleState.hidden:
case AppLifecycleState.paused:
return DVAppLifecycle.backgrounded;
// The settled state, not the transition into it. Reporting `resuming`
// here would name a moment that has already passed, and an application
// waiting for `ready` would never get it.
case AppLifecycleState.resumed:
return DVAppLifecycle.ready;
case AppLifecycleState.detached:
return DVAppLifecycle.shuttingDown;
// A notification banner, the app switcher, an incoming call: the
// application is on screen and about to be interrupted. Calling it
// backgrounded would have an application save a draft and flush its
// state every time a message arrives, and would say the app went away
// when it did not. Nothing is a better answer than a wrong one.
case AppLifecycleState.inactive:
return null;
}
}