If you have been on Facebook, Messenger, Twitter, or telegram, once you open a chat and it loads for the first time it takes some time, close that chat and open it sometime later, it won't load it will open from where you left it as if that page was held in a memory space for use the next time. How can you achieve this in Flutter (and firebase). This even happens when you close the app. Open it on a later date, you'll find it how you left it (on the home page though).
Tried building the state with automaticKeepAliveClient Mixin but that only works for a page that will not be popped, like a navbar page. Also tried pageStorage
, how ironic they only store scroll positions, not the whole page.
What I'm expecting is that when I open a chat with John and a bunch of messages load, it shouldn't load again next time, and when I close the app, pages I've already loaded like the home page should be where I left them, the last session. This would improve the UX of the app 10x.
You should check out Flutter Preferences for local storage to help you save data And also use AppLifecycleState to listen when AppLifecycleState.paused, AppLifecycleState.inactive or AppLifecycleState.resumed
When app is paused or inactive, save data in preferences, when it has resumed, continue from the last time saved data and state since last time app was inactive or paused.
The state exists while the page (route) is in memory, and once you remove the page from memory, the state loses its data. It's like the computer RAM - the application is stored in the RAM and once it's not used, that memory is freed up. In order to persist data, I would suggest using local storage (saving to the device and loading from it). Here is the link to the following articl:https://stackoverflow.com/questions/41369633/how-to-save-to-local-storage-using-flutter