My app uses path_provider’s getApplicationDocumentsDirectory
to get the documents folder so I can save and edit some json files. That works fine on Android and iOS but I am struggling to get that to work on Chrome/Any Browser.
Is there an alternative?
This is how I use at the moment:
static loadDirectory() async =>
directory = await getApplicationDocumentsDirectory();
and then (for example):
removeFile(String fileName) {
File file = File("${directory.path}/$fileName.json");
if (file.existsSync()) file.delete();
}
What’s the approach for save/maintain files when dealing with browsers (I am considering to move my app to a website)
Thanks in advance
2
Answers
@Icaroto On web,
path_provider
can’t directly access the file system like on Android and iOS due to security restrictions. For basic tasks like saving JSON files, opt forLocalStorage
. For complex file operations, utilize web APIs for file handling.If you want to store a small amount of data you can use
shared_preferences
package. This package supports all platforms and you don’t need to deal with different platforms by yourself.https://pub.dev/packages/shared_preferences