0

how to save state in flutter am trying to make a quantity number which is displayed in text widge there is plus and minus button once I go back from the page the quantity becomes zero even though i have made it any other number

3 Answers 3

1

Since your use case is simple , it only requires storing the requisite data to JSON or UTF-8 and writing this data to an editable File.

1.Saving data as JSON
The dart:convert library has converters for JSON and UTF-8, as well as support for creating additional converters. JSON is a simple text format for representing structured objects and collections. UTF-8 is a common variable-width encoding that can represent every character in the Unicode character set.

2.Creating and saving to an editable File
The I/O library enables command-line apps to read and write files and browse directories.

Sign up to request clarification or add additional context in comments.

Comments

0

When asking questions on StackOverflow, it's generally preferred to share some code that you have tried.

In your case, it's likely that you need to use setState in your widget somewhere to modify the value of a variable in your widget class. But without seeing your code, it will be difficult to answer completely.

Comments

-1

You can used the provider package in Flutter to manage your application state. Here is the link to the provider package and it's documentation.

Provider Package

Provider Documentation

2 Comments

am able to change the value but when I close the app and open it again or if I go to another screen the value is lost I have used the set state to change the state
Yes, that would happen because you are not saving the data locally. When you close the app. All the data goes away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.