提交 f8d0d395 authored 作者: 张国庆's avatar 张国庆

feat:1.支持文件配置2.下载完成直接安装

上级 1e53a0d8
...@@ -45,7 +45,7 @@ class _MyAppState extends State<MyApp> { ...@@ -45,7 +45,7 @@ class _MyAppState extends State<MyApp> {
}; };
ApkUpdate().updateApp( ApkUpdate().updateApp(
url: url:
"https://gateway.devclx.cn/clx-user/app/version/getSystemVersionByNumber", "https://gateway.testclx.cn/clx-user/app/version/getSystemVersionByNumber",
params: { params: {
"versionNumber": 1, "versionNumber": 1,
"productNo": 1, "productNo": 1,
......
...@@ -77,7 +77,7 @@ class ApkUpdate { ...@@ -77,7 +77,7 @@ class ApkUpdate {
debugPrint("===== installApk"); debugPrint("===== installApk");
ApkUpdatePlatform.instance.installApk(path); ApkUpdatePlatform.instance.installApk(path);
}, },
downloadApk: (String? path) { downloadApk: (String? path, String? apkPath) {
final dio = Dio(); final dio = Dio();
dio dio
.get("${paramsOSS?['baseUrl']}$generateByExt", .get("${paramsOSS?['baseUrl']}$generateByExt",
...@@ -100,7 +100,7 @@ class ApkUpdate { ...@@ -100,7 +100,7 @@ class ApkUpdate {
var ak = map?['onceAccessKeyId']; var ak = map?['onceAccessKeyId'];
var sk = map?["onceAccessKeySecret"]; var sk = map?["onceAccessKeySecret"];
var token = map?["onceSecurityToken"]; var token = map?["onceSecurityToken"];
var objectKey = paramsOSS?["objectKey"]; var objectKey = apkPath ?? "";
var endpoint = paramsOSS?["endpoint"]; var endpoint = paramsOSS?["endpoint"];
var bucketName = paramsOSS?["bucketName"]; var bucketName = paramsOSS?["bucketName"];
var localPath = path; var localPath = path;
......
...@@ -30,7 +30,7 @@ void checkVersion( ...@@ -30,7 +30,7 @@ void checkVersion(
Function()? jumpAppStore, // 跳转AppStore Function()? jumpAppStore, // 跳转AppStore
Function(String? path)? installApk, // 安装Apk Function(String? path)? installApk, // 安装Apk
Function()? downloadApkError, // 下载Apk错误 Function()? downloadApkError, // 下载Apk错误
Function(String? path)? downloadApk, // 使用OSS下载Apk Function(String? path,String? apkPath)? downloadApk, // 使用OSS下载Apk
int? isOssDownload //1 使用OSS下载 int? isOssDownload //1 使用OSS下载
}) async { }) async {
try { try {
......
...@@ -18,7 +18,7 @@ class UpdateDialog extends StatefulWidget { ...@@ -18,7 +18,7 @@ class UpdateDialog extends StatefulWidget {
final Function()? jumpAppStore; // 跳转AppStore final Function()? jumpAppStore; // 跳转AppStore
final Function(String? path)? installApk; // 安装Apk final Function(String? path)? installApk; // 安装Apk
final int? isOssDownload; //1 使用OSS下载 final int? isOssDownload; //1 使用OSS下载
final Function(String? path)? downloadApk; // 使用OSS下载Apk final Function(String? path,String? apkPath)? downloadApk; // 使用OSS下载Apk
final Function()? downloadApkError; // 下载Apk错误 final Function()? downloadApkError; // 下载Apk错误
const UpdateDialog({ const UpdateDialog({
...@@ -213,6 +213,17 @@ class _UpdateDialogState extends State<UpdateDialog> { ...@@ -213,6 +213,17 @@ class _UpdateDialogState extends State<UpdateDialog> {
await DirectoryUtil.getInstance(); await DirectoryUtil.getInstance();
DirectoryUtil.createStorageDirSync(category: 'Download'); DirectoryUtil.createStorageDirSync(category: 'Download');
String? path = DirectoryUtil.getStoragePath(category: 'Download'); String? path = DirectoryUtil.getStoragePath(category: 'Download');
File apkFile = File("$path/${widget.versionPath}");
File apkFileTmp = File("$path/${widget.versionPath}.tmp");
// 判断localPath 下有没有下载完成的文件
if (apkFile.existsSync() && !apkFileTmp.existsSync()) {
ApkUpdatePlatform.instance.installApk(apkFile.path);
_isDownload = false;
setState(() {});
return;
}
_subscription = _subscription =
ApkUpdatePlatform.instance.addDownloadListener().listen((event) { ApkUpdatePlatform.instance.addDownloadListener().listen((event) {
var count = event['currentSize'] as num; var count = event['currentSize'] as num;
...@@ -225,7 +236,7 @@ class _UpdateDialogState extends State<UpdateDialog> { ...@@ -225,7 +236,7 @@ class _UpdateDialogState extends State<UpdateDialog> {
setState(() {}); setState(() {});
}); });
widget.downloadApk?.call(path); widget.downloadApk?.call(path, widget.versionPath);
return; return;
} }
setInitDir(initStorageDir: true); setInitDir(initStorageDir: true);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论