I am trying to write to and read from a file that is in the assets folder in a flutter app. Generally, how should it be done? I tried the following approach:-
void writeToFile(String data) async {
final String filename = 'colors.json';
await rootBundle.load('assets/docs/colors.json').then((f){
print("file loaded successfully.");
File file = File(filename);
file.writeAsString(data);
});
}
However, this results in the following error: E/flutter ( 4944): FileSystemException: Cannot open file, path = 'colors.json' (OS Error: Read-only file system, errno = 30)
OS: Mac Catalina
pubspec entry:
assets:
- assets/docs/colors.json