could you write to local asset files? I have managed to retrieve information from a local json file but was wondering if you could write to the file? and if so how?
would it be better to write to local preferences or is this too small for large amounts of data?
if you are reading/writing to a local file, how would you test this with the emulator? I am receiving error messages that I can not access the files.

- 484,302
- 314
- 1,365
- 1,393

- 161
- 3
- 6
-
https://stackoverflow.com/questions/41369633/how-can-i-save-to-local-storage-using-flutter – Suragch Dec 31 '18 at 14:39
1 Answers
You can write to local files within the app's private sandboxed directory (NSDocumentsDirectory
on iOS, AppData
on Android), but NOT to files that are bundled within the app itself (This doesn't mean you can't package read/write files within the app, though: If you want to write to a pre-packaged file, you must first copy it to the documents directory and use the new copy as your "writable" version). In addition to addressing security concerns, this ensures that the original app bundle remains intact and can be updated/replaced without affecting any user data.
Take a look at the Flutter cookbook entry here for more details on writing to local storage.
For a discussion of the pros and cons of writing to local preferences (which should be reserved for smaller data bits) check out this question and its answers.

- 5,487
- 4
- 24
- 28
-
This works for storing a single value but how would I then write a list to the file instead of a single value? I would like to save a number of different lists, then change and update specific list items. I am getting confused with the process of saving lists to file and then returning lists from a file. would you use \n at the end of the string and then use read as lines? – Christopher Smith Jun 08 '18 at 11:33
-
The example in the cookbook does indeed use a single integer as an example , but you can write (and read) any string to/from this file. Then, using a serializer/deserializer (For example, [this one](https://pub.dartlang.org/packages/jaguar_serializer)), you can convert just about any object or array (ie, "map") into a JSON string which can then be saved and/or retrieved later. To be fair, a discussion of the many ways to store/retrieve data in various formats far exceeds the scope of a single question, though. – Mike Fahy Jun 08 '18 at 16:53