onBackground method

Future<void> onBackground()

Saves the current state and a timestamp to storage when the app enters the background.

This should be called from the didChangeAppLifecycleState method in your UI layer when the state is AppLifecycleState.paused.

Implementation

Future<void> onBackground() async {
  final timestamp = currentTimeStampInEpoch();
  await storageManager.backGroundTimeStampStorage.saveSeconds(timestamp);
  await storageManager.timerStorage.saveSeconds(state.secondsRemaining);
  emit(
    TimerState(
      isRunning: false,
      secondsRemaining: state.secondsRemaining,
      isPaused: true,
    ),
  );
  _timer?.cancel();
}