I am workin on a flutter web project and I want to generate json configuration files automatically inside the poject devepending on the environment (dev, acc, prod) using envied variables when I run the app. Is this possible?
Asked
Active
Viewed 124 times
1 Answers
0
try this:
import 'dart:io';
import 'dart:convert';
void main() {
final file = File('file.json');
final data = {
'name': 'Foo',
'age': 42,
};
final content = json.encode(data);
file.writeAsStringSync(content);
}

Hydra
- 550
- 2
- 6
-
Yes but I think dart.io is not supported for web so the data won't be written in the file – hajer Dec 07 '22 at 15:02
-
check this out then, maybe the solutions will be of help. https://stackoverflow.com/questions/57182634/to-read-and-write-file-in-flutter-web – Etornam Dec 07 '22 at 15:10
-
@Etornam this writes a file by sending the user an auto-download. For my case I want to edit the local file automatically in background. – hajer Dec 07 '22 at 15:21