flowder
flowder copied to clipboard
Re-downloading a file appends to itself instead of overwriting
Hi, when I re-download a file, the file appends to itself instead of overwriting it. For example, if I have an already downloaded file that is 10MB in size and I redownload the file, its size will be 20 MB instead of the same 10 MB. I could use a check to see if the file exists, but the file should still be overwritten instead of appended to itself. Also, if the internet connection fails, the incomplete download does not get deleted.
Here's my code:
if (await InternetConnectionChecker().hasConnection) {
final downloaderUtils = DownloaderUtils(
progressCallback: (current, total) async {
final int progress = ((current / total) * 100).toInt();
if (progress == 100) {
await flutterLocalNotificationsPlugin.cancel(123);
}
},
file: File(filePath),
progress: ProgressImplementation(),
// ignore: avoid_print
onDone: () {
SnackBar downloadFinished = SnackBar(
content: Text("Finished downloading $itemName"),
behavior: SnackBarBehavior.floating,
duration: Duration(seconds: 3),
);
ScaffoldMessenger.of(context).showSnackBar(downloadFinished);
},
deleteOnCancel: true,
);
final core = await Flowder.download(fileUrl, downloaderUtils);
await flutterLocalNotificationsPlugin.show(123, "Downloading file $itemName, \nplease wait.", "", notificationDetails);
} else {
await flutterLocalNotificationsPlugin.cancel(123);
SnackBar downloadFailed = SnackBar(
content: Text("Download of $itemName failed. Please try again"),
behavior: SnackBarBehavior.floating,
duration: Duration(seconds: 3),
);
ScaffoldMessenger.of(context).showSnackBar(downloadFailed);
}