Flutter Web Download Zip File

Viewed 70

I am trying to create multiple files and insert them into a zip file for download in Flutter Web. I am not sure how to go about this.

I have the following code to generate a json file for download.

void download(String json) {
    final content = base64Encode(utf8.encode(json));
    AnchorElement(
        href: "data:application/octet-stream;charset=utf-16le;base64,$content")
      ..setAttribute("download", "file.json")
      ..click();
  }

I now want to know how can I generate somethings like "files.zip" and inside this zip is a list of json files or whatever files.

I was thinking of using the following:

void zip(){
    var encoder = ZipFileEncoder();
    io.File();
    encoder.create(appDocDirectory.path+"/"+'files.zip');
    encoder.addFile(io.File(selectedAdharFile));
    encoder.addFile(File(selectedIncomeFile));

  }
0 Answers
Related