handleLifecycleEvent method
Called by the registered RoyLifecycleCoordinator hook — exposed
publicly (rather than private) so a caller without a coordinator can
drive it directly, and so tests can too without standing up a full
WidgetsBinding observer.
Implementation
void handleLifecycleEvent(RoyLifecycleEvent event) {
if (event == RoyLifecycleEvent.background) {
_accumulatedForeground += _foregroundStopwatch.elapsed;
_foregroundStopwatch
..stop()
..reset();
_backgroundedAtMs = nowMsClamped();
return;
}
final backgroundedAt = _backgroundedAtMs;
_backgroundedAtMs = null;
final awayMs = backgroundedAt == null ? 0 : nowMsClamped() - backgroundedAt;
if (awayMs >= sessionTimeout.inMilliseconds) {
_startNewSession();
} else {
_foregroundStopwatch.start();
}
}