didChangeAppLifecycleState method
Function called when the app changes the lifecycle state. @param state The new app state.
Implementation
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state != AppLifecycleState.resumed) {
_sessionManager.endSession();
} else {
bool shouldStartSession = _lastResumedDate == null;
if (_lastResumedDate != null) {
shouldStartSession = DateTime.now().difference(_lastResumedDate!) >
const Duration(seconds: 30);
}
if (shouldStartSession) {
_lastResumedDate = DateTime.now();
_sessionManager.startSession().then(
(_) => updateMetadata(),
);
}
}
}