How can we dynamically create a text file for download using Dart without involving the server?
Asked
Active
Viewed 727 times
1 Answers
4
This question has already been asked and answered for JS. Very similar solutions to those in that thread apply to Dart with very little modification. For example we could create an anchor element with a custom data URI and either present it to the user or call its click
method:
String encodedFileContents = Uri.encodeComponent("Hello World!");
new AnchorElement(href: "data:text/plain;charset=utf-8,$encodedFileContents")
..setAttribute("download", "file.txt")
..click();
See DartPad example that allows the user to edit a table element's cells and then download the cell contents as a csv file.

Community
- 1
- 1

Richard Ambler
- 4,816
- 2
- 21
- 38
-
How might this be done if you want to generate a very very large file? i.e. can we stream the file rather than store it all in memory? – Krolaw Sep 12 '19 at 02:33