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?
To delete a file, first create a reference to that file. Then call the delete() method on that reference. await desertRef. delete();
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With