Reputation: 33
I want to delete files from any folders of android device using flutter programatically. Is there any way to delete files created as in the code. I downloaded files using dio. and want to delete the files downloaded like this.
var dir = await getExternalStorageDirectory(); await dio.download(fileURL, "${dir.path}/books/$fileName.pdf",
Upvotes: 3
Views: 3326
Reputation: 1452
If you want to delete the file after a button pressed, this is what I suggest:
onPressed: () async {
Directory dir = await getExternalStorageDirectory();
final targetFile = Directory("${dir.path}/books/$fileName.pdf");
if(targetFile.existsSync()) {
targetFile.deleteSync(recursive: true);
}
}
Upvotes: 4