download static method
Implementation
static Future download(String url) async {
// 初始化 FlutterDownloader
await FlutterDownloader.initialize();
final per = await PermissionHelper.checkPermission([Permission.storage]);
if (!per) {
CommonHelper.showToast("Please enable related permissions");
}
final path = await _apkLocalPath;
PackageInfo packageInfo = await getPackageInfo();
File file = File(path + '/' + packageInfo.appName);
if (await file.exists()) await file.delete();
WidgetsFlutterBinding.ensureInitialized();
await FlutterDownloader.initialize();
CommonHelper.showToast("Start download");
final taskId = await FlutterDownloader.enqueue(
url: url,
savedDir: path,
fileName: packageInfo.appName,
showNotification: true,
openFileFromNotification: true);
FlutterDownloader.registerCallback((id, status, progress) {
DownloadTaskStatus downloadTaskStatus = DownloadTaskStatus.values[status];
if (downloadTaskStatus == DownloadTaskStatus.failed) {
CommonHelper.showToast("Download failed");
}
if (taskId == id && downloadTaskStatus == DownloadTaskStatus.complete) {
CommonHelper.showToast("Download complete");
_installApk();
}
});
}