download function
Future<String?>
download({
- dynamic fileName,
- dynamic url,
- dynamic directory,
- bool isOpen = false,
- dynamic context,
Implementation
Future<String?> download({fileName, url, directory, bool isOpen = false, bool isShare = false, context}) async {
String? id;
if (await File(directory + '/' + fileName).exists()) {
} else {
// _onLoading(context);
String? data = await FlutterDownloader.enqueue(
url: url,
savedDir: directory,
requiresStorageNotLow: true,
saveInPublicStorage: true,
fileName: fileName,
showNotification: false, // show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);
id = data;
}
delayed = Timer.periodic(const Duration(seconds: 1), (times) async {
try {
if (!isLoad) {
isLoad = true;
final bool status = await getDownloadfile(fileName);
if (status) {
if (isOpen) {
OpenFile.open(directory + '/' + fileName);
} else if (isShare) {
Share.shareFiles([directory + '/' + fileName]);
}
isLoad = false;
delayed!.cancel();
} else {
isLoad = false;
}
}
} catch (_) {
print(_);
delayed!.cancel();
if (isOpen) {
OpenFile.open(directory + '/' + fileName);
} else if (isShare) {
Share.shareFiles([directory + '/' + fileName]);
}
}
});
return id;
}