Home > Software design >  How long does Provider data persist
How long does Provider data persist

Time:01-04

If I use providers in my flutter project and set data for my different providers how long do they persist for?

If I backgrounded my app will it persist no matter how long I have it in the background? If I killed my app and reopened it will the provider data still persist or will it be gone? If I want the provider data to persist regardless if the app is backgrounded or killed and only be cleared when an user logs out of an app, what is the best way of doing so?

Thanks!

CodePudding user response:

1.If I use providers in my flutter project and set data for my different providers how long do they persist for? Ans: During the whole app lifecycle. If you killed and re-opened the app all the provider re-initialized and previous data will be lost.

  1. If I backgrounded my app will it persist no matter how long I have it in the background? Ans: As long as app is in background the data will be persist.

For your kind information provider doesn't have any philosophical connection or usefulness with data persistency .It is used for app state management. One of the best case for understanding provider is suppose you have some data on server, You have to request it from server then you will have the data. After having this data you will update your UI to show this data to your user. As you can see here your app is passing different app state from request to receive this data from server and regarding this you have to update your UI like showing a Loader while requesting and when you have data just update UI and render your data to screen. Provider do this whole bunch of things or manage your sate. For better understanding provider you can read this article Simple app state management

  •  Tags:  
  • Related