Aman Chaudhary
Aman Chaudhary

Reputation: 912

How to not lose the updated variable in flutter?

Situation

I have a variable called number = 0 in my stateful widget in the second screen. Now, when a plus button is pressed it increases by 1 every time. Now when I go to first screen and come back to the second screen the variable again starts from 0 which I don't want.

Needed

When came back to second screen from first screen. I should have the updated variable.

How can I do that?

Upvotes: 0

Views: 53

Answers (1)

Bensal
Bensal

Reputation: 4110

Try to create a static variable instead of a normal variable.

You can also try initializing the static variable in the first screen and pass it as an argument for better control.

But if you want the variable to be same even after reopening the app, you will have to save it to internal memory.

Hope it works!

Upvotes: 1

Related Questions