Search code examples
flutterdarttimer

How To Save The State Of A Page To Phone Flutter


I'm currently making a timer page that lists your times when you start and stop, but when i close the page or restart the app all the times disappear. I want to know how i can save the state of the page so it just returns back with all the times on the page. Here is my project.


Solution

  • You should check out Flutter Preferences for local storage to help you save timeStamps And also use AppLifecycleState to listen when AppLifecycleState.paused, AppLifecycleState.inactive or AppLifecycleState.resumed

    When app is paused or inactive, save timer in preferences, when it has resumed, continue from the last time saved plus the time difference since last time app was inactive or paused.