A way to store the variables last value so that it can be used when app is restarted?

Viewed 68

I came across this question/doubt while coding my app, that on hot restart the app is initialised again which runs all the initState(){} and the last value of the variables is lost.

I know that the state of the app is lost on the hot restart or in practical use case when the app is removed from the recent apps and launched again, So the variables that I have declared are also reinitialised because the whole code runs again,

and the ones which are just defined and not initialised like String path;' and is given null` values which cause an error in the code.

So I just want to make sure that is this true for every app and is there a way to store the variables last stored value which can be used when the app is restarted?

I am currently thinking of using a text file to store such variables value.

So can sharedPreference plugin overcome this?

0 Answers
Related