Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - include a zip file with an app and delete it at after processing (can I delete Assets at runtime?)

Tags:

flutter

I want to include a zip file in my flutter app. When the user runs the app for the first time, I will process that zip file (saving the contents using getApplicationDocumentsDirectory() for example) and then I will want to delete the zip file...to save space on the user's machine.

Is it possible to delete an asset at runtime?

Or is there another way to achieve including a file in the installation and then deleting it at runtime?

like image 706
atreeon Avatar asked Jul 13 '18 18:07

atreeon


People also ask

How do I delete files on flutter?

To delete a file, first create a reference to that file. Then call the delete() method on that reference. await desertRef. delete();


1 Answers

Yes, this is straightforward. In your first widget which is run at startup you could detect if the file exists and then delete with :

File file = new File((await getApplicationDocumentsDirectory()).path + "myfile.zip");
if (file.existsSync()) {
  file.delete();
}

Or you could use preferences to store a flag when it is deleted (and check the flag at startup).

like image 137
Rockvole Avatar answered Oct 06 '22 08:10

Rockvole