Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
apk_update
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
apk_update
Commits
f01f7c6d
提交
f01f7c6d
authored
6月 21, 2025
作者:
史晓晨
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:优化代码
上级
4ae8e1af
显示空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
816 行增加
和
478 行删除
+816
-478
apk_update.dart
lib/apk_update.dart
+165
-176
constants.dart
lib/core/common/constants.dart
+6
-0
servier_api.dart
lib/core/common/servier_api.dart
+18
-0
version_info.dart
lib/core/common/version_info.dart
+34
-0
carrier_version_service.dart
...ore/services/version_service/carrier_version_service.dart
+65
-0
msl_version_service.dart
lib/core/services/version_service/msl_version_service.dart
+65
-0
pm_version_service.dart
lib/core/services/version_service/pm_version_service.dart
+87
-0
version_service.dart
lib/core/services/version_service/version_service.dart
+21
-0
check_version.dart
lib/utils/check_version/check_version.dart
+243
-0
dio_update_util.dart
lib/utils/dio_update_util.dart
+92
-5
utils.dart
lib/utils/utils.dart
+20
-297
没有找到文件。
lib/apk_update.dart
浏览文件 @
f01f7c6d
...
@@ -6,6 +6,9 @@ import 'package:apk_update/utils/utils.dart';
...
@@ -6,6 +6,9 @@ import 'package:apk_update/utils/utils.dart';
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:url_launcher/url_launcher.dart'
;
import
'package:url_launcher/url_launcher.dart'
;
import
'apk_update_platform_interface.dart'
;
import
'apk_update_platform_interface.dart'
;
import
'core/common/constants.dart'
;
import
'core/common/servier_api.dart'
;
import
'utils/check_version/check_version.dart'
;
class
ApkUpdate
{
class
ApkUpdate
{
/// 检测应用版本(老版本方法)
/// 检测应用版本(老版本方法)
...
@@ -26,43 +29,29 @@ class ApkUpdate {
...
@@ -26,43 +29,29 @@ class ApkUpdate {
Function
()?
downloadApkError
,
// 下载Apk错误
Function
()?
downloadApkError
,
// 下载Apk错误
})
{
})
{
//App2.vipApp,3,vip-pc。4,马上富通。5,马上富通pc。6,微信货主。7,货主pc。8,马上审。默认为1
//App2.vipApp,3,vip-pc。4,马上富通。5,马上富通pc。6,微信货主。7,货主pc。8,马上审。默认为1
checkVersion
(
// checkVersion(
url:
"
$baseUrl$getSystemVersionByNumber
"
,
// url: "$baseUrl${ServerApi.getSystemVersionByNumber}",
method:
Method
.
get
,
// method: Method.get,
params:
{
"versionNumber"
:
versionNumber
,
"productNo"
:
productNo
},
// params: {"versionNumber": versionNumber, "productNo": productNo},
isOssDownload:
paramsOSS
!=
null
?
1
:
0
,
// isOssDownload: paramsOSS != null ? 1 : 0,
onceDay:
onceDay
,
// onceDay: onceDay,
jumpAppStore:
()
{
// jumpAppStore: () {
// 跳转AppStore
// // 跳转AppStore
debugPrint
(
"===== jumpAppStore"
);
// debugPrint("===== jumpAppStore");
_jumpAppStore
(
appleId
);
// jumpAppStore(appleId);
},
// },
installApk:
(
String
?
path
)
{
// installApk: (String? path) {
// 安装Apk
// // 安装Apk
debugPrint
(
"===== installApk"
);
// debugPrint("===== installApk");
ApkUpdatePlatform
.
instance
.
installApk
(
path
);
// ApkUpdatePlatform.instance.installApk(path);
},
// },
downloadApkError:
()
{
// downloadApkError: () {
// 下载Apk错误
// // 下载Apk错误
debugPrint
(
"===== downloadApkError"
);
// debugPrint("===== downloadApkError");
// 项目中没有依赖toast,自己项目中实现
// // 项目中没有依赖toast,自己项目中实现
downloadApkError
?.
call
();
// downloadApkError?.call();
},
// },
);
// );
}
// 跳转 App Store 详情
_jumpAppStore
(
String
id
)
async
{
String
url
=
"https://apps.apple.com/cn/app/id
$id
"
;
final
uri
=
Uri
.
parse
(
url
);
if
(
await
canLaunchUrl
(
uri
))
{
await
launchUrl
(
uri
,
mode:
LaunchMode
.
externalApplication
,
);
return
;
}
}
}
/// 升级版本(新)
/// 升级版本(新)
...
@@ -78,72 +67,72 @@ class ApkUpdate {
...
@@ -78,72 +67,72 @@ class ApkUpdate {
Map
<
String
,
dynamic
>?
paramsOSS
,
Map
<
String
,
dynamic
>?
paramsOSS
,
Function
()?
downloadApkError
,
// 下载Apk错误
Function
()?
downloadApkError
,
// 下载Apk错误
})
{
})
{
checkVersion
(
//
checkVersion(
url:
url
,
//
url: url,
method:
Method
.
post
,
//
method: Method.post,
params:
params
,
//
params: params,
isOssDownload:
paramsOSS
!=
null
?
1
:
0
,
//
isOssDownload: paramsOSS != null ? 1 : 0,
header:
{
"product-code"
:
params
[
"productCode"
]},
//
header: {"product-code": params["productCode"]},
onceDay:
onceDay
,
//
onceDay: onceDay,
jumpAppStore:
()
{
//
jumpAppStore: () {
// 跳转AppStore
//
// 跳转AppStore
debugPrint
(
"===== jumpAppStore"
);
//
debugPrint("===== jumpAppStore");
_
jumpAppStore
(
appleId
);
//
jumpAppStore(appleId);
},
//
},
installApk:
(
String
?
path
)
{
//
installApk: (String? path) {
// 安装Apk
//
// 安装Apk
debugPrint
(
"===== installApk"
);
//
debugPrint("===== installApk");
ApkUpdatePlatform
.
instance
.
installApk
(
path
);
//
ApkUpdatePlatform.instance.installApk(path);
},
//
},
downloadApk:
(
String
?
path
,
String
?
apkPath
)
async
{
//
downloadApk: (String? path, String? apkPath) async {
DioUpdateUtil
.
getDio
()
//
DioUpdateUtil.getDio()
.
get
(
"
${paramsOSS?['baseUrl']}$generateByExt
"
,
// .get("${paramsOSS?['baseUrl']}${ServerApi.generateByExt}
",
queryParameters:
{
//
queryParameters: {
"extension"
:
"apk"
,
//
"extension": "apk",
"bucketName"
:
paramsOSS
?[
"bucketName"
]
//
"bucketName": paramsOSS?["bucketName"]
},
//
},
options:
Options
(
headers:
{
//
options: Options(headers: {
"token"
:
paramsOSS
?[
'token'
],
//
"token": paramsOSS?['token'],
"product-code"
:
params
[
"productCode"
]
//
"product-code": params["productCode"]
}))
//
}))
.
then
((
res
)
{
//
.then((res) {
if
(
res
.
data
==
null
||
res
.
data
is
String
)
{
//
if (res.data == null || res.data is String) {
debugPrint
(
'获取OSS授权失败:
${res.data}
'
);
//
debugPrint('获取OSS授权失败: ${res.data}');
downloadApkError
?.
call
();
//
downloadApkError?.call();
return
;
//
return;
}
//
}
var
map
=
res
.
data
[
'data'
];
//
var map = res.data['data'];
// 使用OSS下载
//
// 使用OSS下载
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
=
apkPath
??
""
;
//
var objectKey = apkPath ?? "";
// apkPath https://mslapp-download.oss-cn-beijing.aliyuncs.com/msl-chengyun.apk 截取后:msl-chengyun.apk
//
// apkPath https://mslapp-download.oss-cn-beijing.aliyuncs.com/msl-chengyun.apk 截取后:msl-chengyun.apk
objectKey
=
objectKey
.
substring
(
objectKey
.
lastIndexOf
(
"/"
)
+
1
);
//
objectKey = objectKey.substring(objectKey.lastIndexOf("/") + 1);
//
var
endpoint
=
paramsOSS
?[
"endpoint"
];
//
var endpoint = paramsOSS?["endpoint"];
var
bucketName
=
paramsOSS
?[
"bucketName"
];
//
var bucketName = paramsOSS?["bucketName"];
var
localPath
=
path
;
//
var localPath = path;
if
(
localPath
==
null
)
{
//
if (localPath == null) {
// 项目中没有依赖toast,自己项目中实现
//
// 项目中没有依赖toast,自己项目中实现
downloadApkError
?.
call
();
//
downloadApkError?.call();
return
;
//
return;
}
//
}
ApkUpdatePlatform
.
instance
.
downloadApk
(
// ApkUpdatePlatform.instance.downloadApk(ak, sk, token, objectKey,
ak
,
sk
,
token
,
objectKey
,
endpoint
,
bucketName
,
localPath
,
"fileName"
);
// endpoint, bucketName, localPath,
"fileName");
}).
catchError
((
e
)
{
//
}).catchError((e) {
debugPrint
(
'获取OSS授权失败'
);
//
debugPrint('获取OSS授权失败');
downloadApkError
?.
call
();
//
downloadApkError?.call();
return
;
//
return;
});
//
});
},
//
},
downloadApkError:
()
{
//
downloadApkError: () {
// 下载Apk错误
//
// 下载Apk错误
debugPrint
(
"===== downloadApkError"
);
//
debugPrint("===== downloadApkError");
// 项目中没有依赖toast,自己项目中实现
//
// 项目中没有依赖toast,自己项目中实现
downloadApkError
?.
call
();
//
downloadApkError?.call();
},
//
},
);
//
);
}
}
/// 对接项目管理工具升级功能
/// 对接项目管理工具升级功能
...
@@ -156,78 +145,78 @@ class ApkUpdate {
...
@@ -156,78 +145,78 @@ class ApkUpdate {
bool
onceDay
=
false
,
bool
onceDay
=
false
,
Map
<
String
,
dynamic
>?
paramsOSS
,
Map
<
String
,
dynamic
>?
paramsOSS
,
})
{
})
{
var
params
=
{
//
var params = {
"productCode"
:
productCode
,
//
"productCode": productCode,
"currentVersion"
:
versionNumber
,
//
"currentVersion": versionNumber,
"sideType"
:
Platform
.
isIOS
?
2
:
1
//
"sideType": Platform.isIOS ? 2 : 1
};
//
};
checkVersionPM
(
//
checkVersionPM(
baseUrl:
baseUrl
,
//
baseUrl: baseUrl,
params:
params
,
//
params: params,
onceDay:
onceDay
,
//
onceDay: onceDay,
isOssDownload:
paramsOSS
!=
null
?
1
:
0
,
//
isOssDownload: paramsOSS != null ? 1 : 0,
jumpAppStore:
()
{
//
jumpAppStore: () {
// 跳转AppStore
//
// 跳转AppStore
debugPrint
(
"===== jumpAppStore"
);
//
debugPrint("===== jumpAppStore");
_
jumpAppStore
(
appleId
);
//
jumpAppStore(appleId);
},
//
},
installApk:
(
String
?
path
)
{
//
installApk: (String? path) {
// 安装Apk
//
// 安装Apk
debugPrint
(
"===== installApk"
);
//
debugPrint("===== installApk");
ApkUpdatePlatform
.
instance
.
installApk
(
path
);
//
ApkUpdatePlatform.instance.installApk(path);
},
//
},
downloadApk:
(
String
?
path
,
String
?
apkPath
)
async
{
//
downloadApk: (String? path, String? apkPath) async {
var
objectKey
=
apkPath
??
""
;
//
var objectKey = apkPath ?? "";
//
objectKey
=
getObjectKey
(
objectKey
);
//
objectKey = getObjectKey(objectKey);
DioUpdateUtil
.
getDio
()
//
DioUpdateUtil.getDio()
.
get
(
"
$baseUrl$generateByExt
"
,
// .get("$baseUrl${ServerApi.generateByExt}
",
queryParameters:
{
//
queryParameters: {
"extension"
:
"apk"
,
//
"extension": "apk",
"bucketName"
:
paramsOSS
?[
"bucketName"
]
??
b
ucketName
// "bucketName": paramsOSS?["bucketName"] ?? Constants.ossB
ucketName
},
//
},
options:
Options
(
headers:
{
//
options: Options(headers: {
"token"
:
paramsOSS
?[
'token'
],
//
"token": paramsOSS?['token'],
"product-code"
:
params
[
"productCode"
]
//
"product-code": params["productCode"]
}))
//
}))
.
then
((
res
)
{
//
.then((res) {
if
(
res
.
data
==
null
||
res
.
data
is
String
)
{
//
if (res.data == null || res.data is String) {
debugPrint
(
'获取OSS授权失败:
${res.data}
'
);
//
debugPrint('获取OSS授权失败: ${res.data}');
ToastUtil
.
showToast
(
"获取OSS授权失败,请稍后重新"
);
//
ToastUtil.showToast("获取OSS授权失败,请稍后重新");
return
;
//
return;
}
//
}
var
map
=
res
.
data
[
'data'
];
//
var map = res.data['data'];
// 使用OSS下载
//
// 使用OSS下载
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
localPath
=
path
;
//
var localPath = path;
if
(
localPath
==
null
)
{
//
if (localPath == null) {
ToastUtil
.
showToast
(
"下载路径错误,请稍后重新"
);
//
ToastUtil.showToast("下载路径错误,请稍后重新");
return
;
//
return;
}
//
}
var
localPathFileName
=
getFileName
(
objectKey
);
//
var localPathFileName = getFileName(objectKey);
ApkUpdatePlatform
.
instance
.
downloadApk
(
//
ApkUpdatePlatform.instance.downloadApk(
ak
,
//
ak,
sk
,
//
sk,
token
,
//
token,
objectKey
,
//
objectKey,
paramsOSS
?[
"endpoint"
]
??
e
ndpoint
,
// paramsOSS?["endpoint"] ?? Constants.ossE
ndpoint,
paramsOSS
?[
"bucketName"
]
??
b
ucketName
,
// paramsOSS?["bucketName"] ?? Constants.ossB
ucketName,
localPath
,
//
localPath,
localPathFileName
);
//
localPathFileName);
}).
catchError
((
e
)
{
//
}).catchError((e) {
debugPrint
(
'获取OSS授权失败'
);
//
debugPrint('获取OSS授权失败');
ToastUtil
.
showToast
(
"获取OSS授权失败,请稍后重新"
);
//
ToastUtil.showToast("获取OSS授权失败,请稍后重新");
return
;
//
return;
});
//
});
},
//
},
downloadApkError:
()
{
//
downloadApkError: () {
// 下载Apk错误
//
// 下载Apk错误
debugPrint
(
"===== downloadApkError"
);
//
debugPrint("===== downloadApkError");
ToastUtil
.
showToast
(
"应用更新失败,请稍后重新"
);
//
ToastUtil.showToast("应用更新失败,请稍后重新");
},
//
},
);
//
);
}
}
}
}
lib/core/common/constants.dart
0 → 100644
浏览文件 @
f01f7c6d
class
Constants
{
static
const
spCurrentDay
=
"current_day"
;
static
const
dateFormat
=
"yyyy-MM-dd"
;
static
const
ossEndpoint
=
'oss-cn-beijing.aliyuncs.com'
;
static
const
ossBucketName
=
'clx-prod'
;
}
lib/core/common/servier_api.dart
0 → 100644
浏览文件 @
f01f7c6d
class
ServerApi
{
/// ==================== 老马上来 ====================
// 获取版本号
static
const
String
getSystemVersionByNumber
=
"/user-service/system/version/getSystemVersionByNumber"
;
/// ==================== 项目管理工具 ====================
// 项目管理工 具 版本检测接口
static
const
getLatestByProductCodePM
=
"/pm-process/external/web/onlineConfig/getLatestByProductCode"
;
// 项目管理工具 获取信息版本详情
static
const
getDetailPM
=
"/pm-process/external/web/onlineConfig/getDetail"
;
/// ==================== OSS工具 ====================
// 获取OSS 下载授权ak sk token
static
const
String
generateByExt
=
"/msl-document/common/oss/generateByExt"
;
}
lib/core/common/version_info.dart
0 → 100644
浏览文件 @
f01f7c6d
/// name : ""
/// content : ""
/// versionForce : true
/// versionPath : ""
class
VersionInfo
{
VersionInfo
({
this
.
name
,
this
.
content
,
this
.
versionForce
,
this
.
versionPath
,
});
VersionInfo
.
fromJson
(
dynamic
json
)
{
name
=
json
[
'name'
];
content
=
json
[
'content'
];
versionForce
=
json
[
'versionForce'
];
versionPath
=
json
[
'versionPath'
];
}
String
?
name
;
String
?
content
;
bool
?
versionForce
;
String
?
versionPath
;
Map
<
String
,
dynamic
>
toJson
()
{
final
map
=
<
String
,
dynamic
>{};
map
[
'name'
]
=
name
;
map
[
'content'
]
=
content
;
map
[
'versionForce'
]
=
versionForce
;
map
[
'versionPath'
]
=
versionPath
;
return
map
;
}
}
lib/core/services/version_service/carrier_version_service.dart
0 → 100644
浏览文件 @
f01f7c6d
import
'dart:convert'
;
import
'package:apk_update/core/common/version_info.dart'
;
import
'package:apk_update/core/services/version_service/version_service.dart'
;
import
'package:flustars_flutter3/flustars_flutter3.dart'
;
import
'../../../utils/dio_update_util.dart'
;
import
'../../../utils/toast_util.dart'
;
import
'../../common/constants.dart'
;
/// 承运
class
CarrierVersionServices
implements
VersionService
{
/// 网络全路径
final
String
url
;
/// 请求头
final
Map
<
String
,
dynamic
>?
header
;
/// 请求参数
final
Map
<
String
,
dynamic
>?
params
;
/// 一天提示一次升级标识
final
bool
onceDay
;
const
CarrierVersionServices
({
required
this
.
url
,
this
.
params
,
this
.
header
,
this
.
onceDay
=
false
,
});
@override
Future
<
VersionInfo
?>
checkVersion
()
async
{
var
result
=
await
DioUpdateUtil
.
get
(
url
,
queryParameters:
params
,
headers:
header
);
//获取当前时间
String
spCurrent
=
SpUtil
.
getString
(
Constants
.
spCurrentDay
)
??
""
;
String
current
=
DateUtil
.
formatDate
(
DateTime
.
now
(),
format:
Constants
.
dateFormat
);
//一天提示一次升级 & 非强升 & 当天已提示 => 不再提示
if
(
onceDay
&&
result
?[
'versionForce'
]
==
0
&&
spCurrent
==
current
)
{
// 不再提示
return
null
;
}
//缓存当前时间
SpUtil
.
putString
(
Constants
.
spCurrentDay
,
current
);
// 一天提示一次升级,是在应用首次设置,不需要提示最新版本toast
if
(!
onceDay
&&
result
==
null
)
{
// 当前已经是最新版本
ToastUtil
.
showToast
(
"已经是最新版本了!"
);
return
null
;
}
if
(
result
==
null
)
{
// 无升级任务,拦截
return
null
;
}
// 返回升级版本信息
return
VersionInfo
(
name:
result
[
'versionName'
],
content:
result
[
'tipContent'
]
??
result
[
'versionContent'
],
versionForce:
result
[
'versionForce'
]
==
1
,
versionPath:
result
[
'versionPath'
],
);
}
}
lib/core/services/version_service/msl_version_service.dart
0 → 100644
浏览文件 @
f01f7c6d
import
'dart:convert'
;
import
'package:apk_update/core/common/version_info.dart'
;
import
'package:apk_update/core/services/version_service/version_service.dart'
;
import
'package:flustars_flutter3/flustars_flutter3.dart'
;
import
'../../../utils/dio_update_util.dart'
;
import
'../../../utils/toast_util.dart'
;
import
'../../common/constants.dart'
;
/// 老马上来
class
MSLVersionServices
implements
VersionService
{
/// 网络全路径
final
String
url
;
/// 请求头
final
Map
<
String
,
dynamic
>?
header
;
/// 请求参数
final
Map
<
String
,
dynamic
>?
params
;
/// 一天提示一次升级标识
final
bool
onceDay
;
const
MSLVersionServices
({
required
this
.
url
,
this
.
params
,
this
.
header
,
this
.
onceDay
=
false
,
});
@override
Future
<
VersionInfo
?>
checkVersion
()
async
{
var
result
=
await
DioUpdateUtil
.
get
(
url
,
queryParameters:
params
,
headers:
header
);
//获取当前时间
String
spCurrent
=
SpUtil
.
getString
(
Constants
.
spCurrentDay
)
??
""
;
String
current
=
DateUtil
.
formatDate
(
DateTime
.
now
(),
format:
Constants
.
dateFormat
);
//一天提示一次升级 & 非强升 & 当天已提示 => 不再提示
if
(
onceDay
&&
result
?[
'versionForce'
]
==
0
&&
spCurrent
==
current
)
{
// 不再提示
return
null
;
}
//缓存当前时间
SpUtil
.
putString
(
Constants
.
spCurrentDay
,
current
);
// 一天提示一次升级,是在应用首次设置,不需要提示最新版本toast
if
(!
onceDay
&&
result
==
null
)
{
// 当前已经是最新版本
ToastUtil
.
showToast
(
"已经是最新版本了!"
);
return
null
;
}
if
(
result
==
null
)
{
// 无升级任务,拦截
return
null
;
}
// 返回升级版本信息
return
VersionInfo
(
name:
result
[
'versionName'
],
content:
result
[
'tipContent'
]
??
result
[
'versionContent'
],
versionForce:
result
[
'versionForce'
]
==
1
,
versionPath:
result
[
'versionPath'
],
);
}
}
lib/core/services/version_service/pm_version_service.dart
0 → 100644
浏览文件 @
f01f7c6d
import
'dart:convert'
;
import
'package:apk_update/core/common/version_info.dart'
;
import
'package:apk_update/core/services/version_service/version_service.dart'
;
import
'package:flustars_flutter3/flustars_flutter3.dart'
;
import
'../../../utils/dio_update_util.dart'
;
import
'../../../utils/toast_util.dart'
;
import
'../../common/constants.dart'
;
import
'../../common/servier_api.dart'
;
/// 项目管理工具
class
PMVersionServices
implements
VersionService
{
/// 域名
final
String
baseUrl
;
/// 请求头
final
Map
<
String
,
dynamic
>?
header
;
/// 请求参数
final
Map
<
String
,
dynamic
>?
params
;
/// 一天提示一次升级标识
final
bool
onceDay
;
const
PMVersionServices
({
required
this
.
baseUrl
,
this
.
params
,
this
.
header
,
this
.
onceDay
=
false
,
});
@override
Future
<
VersionInfo
?>
checkVersion
()
async
{
// ①版本检测
var
checkResult
=
await
checkVersionPM
();
// ②获取版本详情
var
result
=
await
getVersionDetailPM
(
checkResult
?[
'id'
]);
// 返回升级版本信息
return
VersionInfo
(
name:
result
[
'name'
],
content:
result
[
'popContent'
],
versionForce:
result
[
'forceUpgradeStatus'
]
==
1
,
versionPath:
result
[
'versionPath'
],
);
}
/// 版本检测
Future
<
dynamic
>
checkVersionPM
()
async
{
var
checkResult
=
await
DioUpdateUtil
.
get
(
"
$baseUrl${ServerApi.getLatestByProductCodePM}
"
,
queryParameters:
params
,
headers:
header
);
// 是否是最新版本提示
final
newVersion
=
int
.
tryParse
(
checkResult
?[
'version'
]?.
toString
()
??
''
)
??
0
;
final
currentVersion
=
int
.
tryParse
(
params
?[
"currentVersion"
]?.
toString
()
??
''
)
??
0
;
if
(
newVersion
<=
currentVersion
)
{
if
(!
onceDay
)
{
ToastUtil
.
showToast
(
'已经是最新版本了!'
);
}
return
null
;
}
return
checkResult
;
}
/// 获取版本详情
Future
<
dynamic
>
getVersionDetailPM
(
int
?
id
)
async
{
var
detailResult
=
await
DioUpdateUtil
.
get
(
"
$baseUrl${ServerApi.getDetailPM}
"
,
queryParameters:
{
'id'
:
id
},
headers:
header
);
// 是否是最新版本提示
final
newVersion
=
int
.
tryParse
(
detailResult
?[
'version'
]?.
toString
()
??
''
)
??
0
;
final
currentVersion
=
int
.
tryParse
(
params
?[
"currentVersion"
]?.
toString
()
??
''
)
??
0
;
if
(
newVersion
<=
currentVersion
)
{
if
(!
onceDay
)
{
ToastUtil
.
showToast
(
'已经是最新版本了!'
);
}
return
null
;
}
return
detailResult
;
}
}
lib/core/services/version_service/version_service.dart
0 → 100644
浏览文件 @
f01f7c6d
import
'package:apk_update/core/common/version_info.dart'
;
import
'../../../utils/connectivity_util.dart'
;
import
'../../../utils/toast_util.dart'
;
/// 版本检测接口
abstract
class
VersionService
{
/// 版本检测
Future
<
VersionInfo
?>
_checkVersion
()
async
{
// 判断网络是否连接
var
resList
=
await
connectivity
.
checkConnectivity
();
if
(
resList
.
isNotEmpty
&&
resList
[
0
]
==
ConnectivityResult
.
none
)
{
ToastUtil
.
showToast
(
"网络异常,请检查网络"
);
return
null
;
}
return
await
checkVersion
();
}
Future
<
VersionInfo
?>
checkVersion
();
}
lib/utils/check_version/check_version.dart
0 → 100644
浏览文件 @
f01f7c6d
// import 'dart:convert';
//
// import 'package:apk_update/utils/connectivity_util.dart';
// import 'package:apk_update/utils/toast_util.dart';
// import 'package:apk_update/widget/update_dialog.dart';
// import 'package:dio/dio.dart';
// import 'package:flustars_flutter3/flustars_flutter3.dart';
// import 'package:get/route_manager.dart';
// import '../../core/common/constants.dart';
// import '../../core/common/servier_api.dart';
//
// /// 获取更新版本信息
// /// url 请求地址
// /// versionNumber 当前应用versionCode
// /// productNo 产品号
// /// onceDay 一天提示一次(应用首页设置true)
// void checkVersion(
// {required String url,
// required Method method,
// Map<String, dynamic>? params,
// Map<String, dynamic>? header,
// bool onceDay = false,
// Function()? jumpAppStore, // 跳转AppStore
// Function(String? path)? installApk, // 安装Apk
// Function()? downloadApkError, // 下载Apk错误
// Function(String? path, String? apkPath)? downloadApk, // 使用OSS下载Apk
// int? isOssDownload //1 使用OSS下载
// }) async {
//
//
// try {
// final Response response = await DioUpdateUtil.getDio().request(
// url,
// options: Options(method: method.value, headers: header),
// queryParameters: params,
// data: params,
// );
// // 网络请求成功
// printLog(response); // 打印日志
// var responseData = response.data;
// if (responseData.runtimeType == String) {
// // 兼容后端数据返回string
// responseData = json.decode(responseData);
// }
// if (responseData?["code"] != 0) {
// ToastUtil.showToast(responseData?["msg"]);
// return;
// }
// var result = responseData?["data"];
// //获取当前时间
// String spCurrent = SpUtil.getString(Constants.spCurrentDay) ?? "";
// String current = DateUtil.formatDate(DateTime.now(), format: Constants.dateFormat);
// //一天提示一次升级 & 非强升 & 当天已提示 => 不再提示
// if (onceDay && result?['versionForce'] == 0 && spCurrent == current) {
// // 不再提示
// return;
// }
// //缓存当前时间
// SpUtil.putString(Constants.spCurrentDay, current);
// // 一天提示一次升级,是在应用首次设置,不需要提示最新版本toast
// if (!onceDay && result == null) {
// // 当前已经是最新版本
// ToastUtil.showToast("已经是最新版本了!");
// return;
// }
// if (result == null) {
// // 无升级任务,拦截
// return;
// }
// // 升级弹框提示
// Get.dialog(
// UpdateDialog(
// title: result['versionName'],
// content: result['tipContent'] ?? result['versionContent'],
// versionForce: result['versionForce'] == 1,
// versionPath: result['versionPath'],
// jumpAppStore: jumpAppStore,
// installApk: installApk,
// isOssDownload: isOssDownload,
// downloadApk: downloadApk,
// downloadApkError: downloadApkError,
// ),
// );
// } on DioException catch (e) {
// printLog(e.response); // 打印日志
// ToastUtil.showToast("服务器请求错误");
// }
// }
//
// /// 检查版本(项目管理工具)
// void checkVersionPM(
// {required String baseUrl,
// Map<String, dynamic>? params,
// bool onceDay = false,
// Function()? jumpAppStore, // 跳转AppStore
// Function(String? path)? installApk, // 安装Apk
// Function()? downloadApkError, // 下载Apk错误
// Function(String? path, String? apkPath)? downloadApk, // 使用OSS下载Apk
// int? isOssDownload //1 使用OSS下载
// }) async {
// // 判断网络是否连接
// var resList = await connectivity.checkConnectivity();
//
// if (resList.isNotEmpty && resList[0] == ConnectivityResult.none) {
// ToastUtil.showToast("网络异常,请检查网络");
// return;
// }
//
// try {
// final Response response = await DioUpdateUtil.getDio().request(
// "$baseUrl${ServerApi.getLatestByProductCodePM}",
// options: Options(
// method: Method.get.value, headers: {"productGroupCode": "common"}),
// queryParameters: params,
// );
// // 网络请求成功
// printLog(response); // 打印日志
// var responseData = response.data;
// if (responseData.runtimeType == String) {
// // 兼容后端数据返回string
// responseData = json.decode(responseData);
// }
// if (responseData?["code"] != 0) {
// ToastUtil.showToast(responseData?["msg"]);
// return;
// }
// var result = responseData?["data"];
// // 是否是最新版本提示
// final newVersion = int.tryParse(result?['version']?.toString() ?? '') ?? 0;
// final currentVersion =
// int.tryParse(params?["currentVersion"]?.toString() ?? '') ?? 0;
// if (newVersion <= currentVersion) {
// if (!onceDay) {
// ToastUtil.showToast('已经是最新版本了!');
// }
// return;
// }
// // 获取新版本详情
// getVersionDetailPM(
// baseUrl: baseUrl,
// id: result?['id'],
// onceDay: onceDay,
// versionNumber: params?["currentVersion"],
// jumpAppStore: jumpAppStore,
// installApk: installApk,
// downloadApkError: downloadApkError,
// downloadApk: downloadApk,
// isOssDownload: isOssDownload,
// );
// } on DioException catch (e) {
// printLog(e.response); // 打印日志
// ToastUtil.showToast("服务器请求错误");
// }
// }
//
// /// 获取版本详情(项目管理工具)
// void getVersionDetailPM({
// required String baseUrl,
// required int? id,
// required bool onceDay,
// required int? versionNumber,
// Function()? jumpAppStore, // 跳转AppStore
// Function(String? path)? installApk, // 安装Apk
// Function()? downloadApkError, // 下载Apk错误
// Function(String? path, String? apkPath)? downloadApk, // 使用OSS下载Apk
// int? isOssDownload, //1 使用OSS下载
// }) async {
// // 判断网络是否连接
// var resList = await connectivity.checkConnectivity();
//
// if (resList.isNotEmpty && resList[0] == ConnectivityResult.none) {
// ToastUtil.showToast("网络异常,请检查网络");
// return;
// }
//
// try {
// final Response response = await DioUpdateUtil.getDio().request(
// "$baseUrl${ServerApi.getDetailPM}",
// options: Options(method: Method.get.value, headers: {
// 'productGroupCode': 'common',
// }),
// queryParameters: {'id': id},
// );
// // 网络请求成功
// printLog(response); // 打印日志
// var responseData = response.data;
// if (responseData.runtimeType == String) {
// // 兼容后端数据返回string
// responseData = json.decode(responseData);
// }
// if (responseData?["code"] != 0) {
// ToastUtil.showToast(responseData?["msg"]);
// return;
// }
// var result = responseData?["data"];
// //获取当前时间
// String spCurrent = SpUtil.getString(Constants.spCurrentDay) ?? "";
// String current = DateUtil.formatDate(DateTime.now(), format: Constants.dateFormat);
// // 是否是强升
// final versionForce = result?['forceUpgradeStatus'] == 1;
// //一天提示一次升级 & 非强升 & 当天已提示 => 不再提示
// if (onceDay && !versionForce && spCurrent == current) {
// // 不再提示
// return;
// }
// //缓存当前时间
// SpUtil.putString(Constants.spCurrentDay, current);
// // 一天提示一次升级,是在应用首次设置,不需要提示最新版本toast
// if (!onceDay && result == null) {
// // 当前已经是最新版本
// ToastUtil.showToast("已经是最新版本了!");
// return;
// }
// // 是否是最新版本提示
// final newVersion = int.tryParse(result?['version']?.toString() ?? '') ?? 0;
// final currentVersion = int.tryParse(versionNumber?.toString() ?? '') ?? 0;
// if (newVersion <= currentVersion) {
// if (!onceDay) {
// ToastUtil.showToast('已经是最新版本了!');
// }
// return;
// }
//
// // 升级弹框提示
// Get.dialog(
// UpdateDialog(
// title: result['name'],
// content: result['popContent'],
// versionForce: result['forceUpgradeStatus'] == 1,
// versionPath: result['versionPath'],
// jumpAppStore: jumpAppStore,
// installApk: installApk,
// isOssDownload: isOssDownload,
// downloadApk: downloadApk,
// downloadApkError: downloadApkError,
// ),
// );
// } on DioException catch (e) {
// printLog(e.response); // 打印日志
// ToastUtil.showToast("服务器请求错误");
// }
// }
\ No newline at end of file
lib/utils/dio_update_util.dart
浏览文件 @
f01f7c6d
import
'dart:convert'
;
import
'package:apk_update/utils/toast_util.dart'
;
import
'package:dio/dio.dart'
;
import
'package:dio/dio.dart'
;
export
'package:dio/dio.dart'
;
import
'package:flutter/material.dart'
;
class
DioUpdateUtil
{
class
DioUpdateUtil
{
// dio 单例对象
static
final
Dio
_dio
=
_initDio
();
static
final
Dio
_dio
=
Dio
();
DioUpdateUtil
.
_internal
();
static
Dio
get
dio
=>
_dio
;
static
Dio
_initDio
()
{
final
dio
=
Dio
();
// 基础配置
dio
.
options
=
BaseOptions
(
connectTimeout:
const
Duration
(
seconds:
15
),
receiveTimeout:
const
Duration
(
seconds:
15
),
contentType:
Headers
.
jsonContentType
,
responseType:
ResponseType
.
plain
);
dio
.
interceptors
.
add
(
LogInterceptor
(
requestBody:
true
,
responseBody:
true
,
));
return
dio
;
}
// GET请求
static
Future
<
dynamic
>
get
(
String
path
,
{
Map
<
String
,
dynamic
>?
queryParameters
,
Map
<
String
,
dynamic
>?
headers
,
})
async
{
try
{
final
Response
response
=
await
_dio
.
get
(
path
,
queryParameters:
queryParameters
,
options:
Options
(
headers:
headers
),
);
return
successCallbackHandler
(
response
);
}
on
DioException
catch
(
e
)
{
debugPrint
(
e
.
message
);
return
null
;
}
}
// POST请求
static
Future
<
dynamic
>
post
(
String
path
,
{
dynamic
data
,
Map
<
String
,
dynamic
>?
queryParameters
,
Map
<
String
,
dynamic
>?
headers
,
})
async
{
try
{
final
Response
response
=
await
_dio
.
post
(
path
,
data:
data
,
queryParameters:
queryParameters
,
options:
Options
(
headers:
headers
),
);
return
successCallbackHandler
(
response
);
}
on
DioException
catch
(
e
)
{
debugPrint
(
e
.
message
);
return
null
;
}
}
static
Dio
getDio
()
{
/// 请求成功处理
return
_dio
;
static
dynamic
successCallbackHandler
(
Response
response
)
{
var
responseData
=
response
.
data
;
if
(
responseData
.
runtimeType
==
String
)
{
// 兼容后端数据返回string
responseData
=
json
.
decode
(
responseData
);
}
if
(
responseData
?[
"code"
]
!=
0
)
{
ToastUtil
.
showToast
(
responseData
?[
"msg"
]);
return
null
;
}
return
responseData
?[
"data"
];
}
}
}
}
// /// 日志打印
// void printLog(Response? response) {
// var responseData = response?.data;
// var requestOptions = response?.requestOptions;
// var headers = response?.headers;
// debugPrint("========== 网络请求响应 ==========\n"
// "statusCode:${response?.statusCode} \n"
// "statusMessage:${response?.statusMessage}\n"
// "method:${requestOptions?.method}\n"
// "path:${requestOptions?.path}\n"
// "headers:${headers?.map}\n\n"
// "queryParameters:${requestOptions?.queryParameters}\n"
// "data:${requestOptions?.data}\n"
// "responseData:$responseData\n");
// }
lib/utils/utils.dart
浏览文件 @
f01f7c6d
import
'dart:convert'
;
import
'package:apk_update/utils/connectivity_util.dart'
;
import
'package:apk_update/utils/toast_util.dart'
;
import
'package:apk_update/widget/update_dialog.dart'
;
import
'package:flustars_flutter3/flustars_flutter3.dart'
;
import
'package:flustars_flutter3/flustars_flutter3.dart'
;
import
'package:flutter/material.dart'
;
import
'package:get/route_manager.dart'
;
import
'package:url_launcher/url_launcher.dart'
;
import
'package:path/path.dart'
as
p
;
import
'package:path/path.dart'
as
p
;
import
'package:url_launcher/url_launcher.dart'
;
import
'dio_update_util.dart'
;
// 获取版本号
const
String
getSystemVersionByNumber
=
"/user-service/system/version/getSystemVersionByNumber"
;
// 项目管理工具 版本检测接口
const
getLatestByProductCodePM
=
"/pm-process/external/web/onlineConfig/getLatestByProductCode"
;
// 项目管理工具 获取信息版本详情
const
getDetailPM
=
"/pm-process/external/web/onlineConfig/getDetail"
;
// 获取OSS 下载授权ak sk token
const
String
generateByExt
=
"/msl-document/common/oss/generateByExt"
;
const
currentDay
=
"current_day"
;
const
dateFormat
=
"yyyy-MM-dd"
;
const
endpoint
=
'oss-cn-beijing.aliyuncs.com'
;
const
bucketName
=
'clx-prod'
;
/// 获取更新版本信息
/// url 请求地址
/// versionNumber 当前应用versionCode
/// productNo 产品号
/// onceDay 一天提示一次(应用首页设置true)
void
checkVersion
(
{
required
String
url
,
required
Method
method
,
Map
<
String
,
dynamic
>?
params
,
Map
<
String
,
dynamic
>?
header
,
bool
onceDay
=
false
,
Function
()?
jumpAppStore
,
// 跳转AppStore
Function
(
String
?
path
)?
installApk
,
// 安装Apk
Function
()?
downloadApkError
,
// 下载Apk错误
Function
(
String
?
path
,
String
?
apkPath
)?
downloadApk
,
// 使用OSS下载Apk
int
?
isOssDownload
//1 使用OSS下载
})
async
{
// 判断网络是否连接
var
resList
=
await
connectivity
.
checkConnectivity
();
if
(
resList
.
isNotEmpty
&&
resList
[
0
]
==
ConnectivityResult
.
none
)
{
ToastUtil
.
showToast
(
"网络异常,请检查网络"
);
return
;
}
try
{
final
Response
response
=
await
DioUpdateUtil
.
getDio
().
request
(
url
,
options:
Options
(
method:
method
.
value
,
headers:
header
),
queryParameters:
params
,
data:
params
,
);
// 网络请求成功
_printLog
(
response
);
// 打印日志
var
responseData
=
response
.
data
;
if
(
responseData
.
runtimeType
==
String
)
{
// 兼容后端数据返回string
responseData
=
json
.
decode
(
responseData
);
}
if
(
responseData
?[
"code"
]
!=
0
)
{
ToastUtil
.
showToast
(
responseData
?[
"msg"
]);
return
;
}
var
result
=
responseData
?[
"data"
];
//获取当前时间
String
spCurrent
=
SpUtil
.
getString
(
currentDay
)
??
""
;
String
current
=
DateUtil
.
formatDate
(
DateTime
.
now
(),
format:
dateFormat
);
//一天提示一次升级 & 非强升 & 当天已提示 => 不再提示
if
(
onceDay
&&
result
?[
'versionForce'
]
==
0
&&
spCurrent
==
current
)
{
// 不再提示
return
;
}
//缓存当前时间
SpUtil
.
putString
(
currentDay
,
current
);
// 一天提示一次升级,是在应用首次设置,不需要提示最新版本toast
if
(!
onceDay
&&
result
==
null
)
{
// 当前已经是最新版本
ToastUtil
.
showToast
(
"已经是最新版本了!"
);
return
;
}
if
(
result
==
null
)
{
// 无升级任务,拦截
return
;
}
// 升级弹框提示
Get
.
dialog
(
UpdateDialog
(
title:
result
[
'versionName'
],
content:
result
[
'tipContent'
]
??
result
[
'versionContent'
],
versionForce:
result
[
'versionForce'
]
==
1
,
versionPath:
result
[
'versionPath'
],
jumpAppStore:
jumpAppStore
,
installApk:
installApk
,
isOssDownload:
isOssDownload
,
downloadApk:
downloadApk
,
downloadApkError:
downloadApkError
,
),
);
}
on
DioException
catch
(
e
)
{
_printLog
(
e
.
response
);
// 打印日志
ToastUtil
.
showToast
(
"服务器请求错误"
);
}
}
/// 检查版本(项目管理工具)
void
checkVersionPM
(
{
required
String
baseUrl
,
Map
<
String
,
dynamic
>?
params
,
bool
onceDay
=
false
,
Function
()?
jumpAppStore
,
// 跳转AppStore
Function
(
String
?
path
)?
installApk
,
// 安装Apk
Function
()?
downloadApkError
,
// 下载Apk错误
Function
(
String
?
path
,
String
?
apkPath
)?
downloadApk
,
// 使用OSS下载Apk
int
?
isOssDownload
//1 使用OSS下载
})
async
{
// 判断网络是否连接
var
resList
=
await
connectivity
.
checkConnectivity
();
if
(
resList
.
isNotEmpty
&&
resList
[
0
]
==
ConnectivityResult
.
none
)
{
ToastUtil
.
showToast
(
"网络异常,请检查网络"
);
return
;
}
try
{
final
Response
response
=
await
DioUpdateUtil
.
getDio
().
request
(
"
$baseUrl$getLatestByProductCodePM
"
,
options:
Options
(
method:
Method
.
get
.
value
,
headers:
{
"productGroupCode"
:
"common"
}),
queryParameters:
params
,
);
// 网络请求成功
_printLog
(
response
);
// 打印日志
var
responseData
=
response
.
data
;
if
(
responseData
.
runtimeType
==
String
)
{
// 兼容后端数据返回string
responseData
=
json
.
decode
(
responseData
);
}
if
(
responseData
?[
"code"
]
!=
0
)
{
ToastUtil
.
showToast
(
responseData
?[
"msg"
]);
return
;
}
var
result
=
responseData
?[
"data"
];
// 是否是最新版本提示
final
newVersion
=
int
.
tryParse
(
result
?[
'version'
]?.
toString
()
??
''
)
??
0
;
final
currentVersion
=
int
.
tryParse
(
params
?[
"currentVersion"
]?.
toString
()
??
''
)
??
0
;
if
(
newVersion
<=
currentVersion
)
{
if
(!
onceDay
)
{
ToastUtil
.
showToast
(
'已经是最新版本了!'
);
}
return
;
}
// 获取新版本详情
getVersionDetailPM
(
baseUrl:
baseUrl
,
id:
result
?[
'id'
],
onceDay:
onceDay
,
versionNumber:
params
?[
"currentVersion"
],
jumpAppStore:
jumpAppStore
,
installApk:
installApk
,
downloadApkError:
downloadApkError
,
downloadApk:
downloadApk
,
isOssDownload:
isOssDownload
,
);
}
on
DioException
catch
(
e
)
{
_printLog
(
e
.
response
);
// 打印日志
ToastUtil
.
showToast
(
"服务器请求错误"
);
}
}
/// 获取版本详情(项目管理工具)
void
getVersionDetailPM
(
{
required
String
baseUrl
,
required
int
?
id
,
required
bool
onceDay
,
required
int
?
versionNumber
,
Function
()?
jumpAppStore
,
// 跳转AppStore
Function
(
String
?
path
)?
installApk
,
// 安装Apk
Function
()?
downloadApkError
,
// 下载Apk错误
Function
(
String
?
path
,
String
?
apkPath
)?
downloadApk
,
// 使用OSS下载Apk
int
?
isOssDownload
,
//1 使用OSS下载
})
async
{
// 判断网络是否连接
var
resList
=
await
connectivity
.
checkConnectivity
();
if
(
resList
.
isNotEmpty
&&
resList
[
0
]
==
ConnectivityResult
.
none
)
{
ToastUtil
.
showToast
(
"网络异常,请检查网络"
);
return
;
}
try
{
final
Response
response
=
await
DioUpdateUtil
.
getDio
().
request
(
"
$baseUrl$getDetailPM
"
,
options:
Options
(
method:
Method
.
get
.
value
,
headers:
{
'productGroupCode'
:
'common'
,
}),
queryParameters:
{
'id'
:
id
},
);
// 网络请求成功
_printLog
(
response
);
// 打印日志
var
responseData
=
response
.
data
;
if
(
responseData
.
runtimeType
==
String
)
{
// 兼容后端数据返回string
responseData
=
json
.
decode
(
responseData
);
}
if
(
responseData
?[
"code"
]
!=
0
)
{
ToastUtil
.
showToast
(
responseData
?[
"msg"
]);
return
;
}
var
result
=
responseData
?[
"data"
];
//获取当前时间
String
spCurrent
=
SpUtil
.
getString
(
currentDay
)
??
""
;
String
current
=
DateUtil
.
formatDate
(
DateTime
.
now
(),
format:
dateFormat
);
// 是否是强升
final
versionForce
=
result
?[
'forceUpgradeStatus'
]
==
1
;
//一天提示一次升级 & 非强升 & 当天已提示 => 不再提示
if
(
onceDay
&&
!
versionForce
&&
spCurrent
==
current
)
{
// 不再提示
return
;
}
//缓存当前时间
SpUtil
.
putString
(
currentDay
,
current
);
// 一天提示一次升级,是在应用首次设置,不需要提示最新版本toast
if
(!
onceDay
&&
result
==
null
)
{
// 当前已经是最新版本
ToastUtil
.
showToast
(
"已经是最新版本了!"
);
return
;
}
// 是否是最新版本提示
final
newVersion
=
int
.
tryParse
(
result
?[
'version'
]?.
toString
()
??
''
)
??
0
;
final
currentVersion
=
int
.
tryParse
(
versionNumber
?.
toString
()
??
''
)
??
0
;
if
(
newVersion
<=
currentVersion
)
{
if
(!
onceDay
)
{
ToastUtil
.
showToast
(
'已经是最新版本了!'
);
}
return
;
}
// 升级弹框提示
Get
.
dialog
(
UpdateDialog
(
title:
result
[
'name'
],
content:
result
[
'popContent'
],
versionForce:
result
[
'forceUpgradeStatus'
]
==
1
,
versionPath:
result
[
'versionPath'
],
jumpAppStore:
jumpAppStore
,
installApk:
installApk
,
isOssDownload:
isOssDownload
,
downloadApk:
downloadApk
,
downloadApkError:
downloadApkError
,
),
);
}
on
DioException
catch
(
e
)
{
_printLog
(
e
.
response
);
// 打印日志
ToastUtil
.
showToast
(
"服务器请求错误"
);
}
}
/// 打开浏览器
Future
<
void
>
openBrowser
(
String
stringUrl
)
async
{
final
Uri
url
=
Uri
.
parse
(
stringUrl
);
if
(!
await
launchUrl
(
url
,
mode:
LaunchMode
.
externalApplication
))
{
throw
Exception
(
'Could not launch
$url
'
);
}
}
/// 处理apk下载url 获取 objectKey
/// 处理apk下载url 获取 objectKey
String
getObjectKey
(
String
url
)
{
String
getObjectKey
(
String
url
)
{
int
startIndex
=
url
.
indexOf
(
"aliyuncs.com/"
)
+
"aliyuncs.com/"
.
length
;
int
startIndex
=
url
.
indexOf
(
"aliyuncs.com/"
)
+
"aliyuncs.com/"
.
length
;
return
url
.
substring
(
startIndex
);
return
url
.
substring
(
startIndex
);
}
}
...
@@ -290,40 +19,34 @@ String getPathByObjectKey(String url) {
...
@@ -290,40 +19,34 @@ String getPathByObjectKey(String url) {
return
p
.
dirname
(
url
);
return
p
.
dirname
(
url
);
}
}
//创建下载目录
//
/
创建下载目录
Future
<
String
?>
createDir
()
async
{
Future
<
String
?>
createDir
()
async
{
setInitDir
(
initStorageDir:
true
);
setInitDir
(
initStorageDir:
true
);
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'
);
return
path
;
return
path
;
}
}
enum
Method
{
/// 打开浏览器
get
,
Future
<
void
>
openBrowser
(
String
stringUrl
)
async
{
post
,
final
Uri
url
=
Uri
.
parse
(
stringUrl
);
put
,
patch
,
delete
,
}
extension
MethodExtension
on
Method
{
if
(!
await
launchUrl
(
url
,
mode:
LaunchMode
.
externalApplication
))
{
String
get
value
=>
[
'GET'
,
'POST'
,
'PUT'
,
'PATCH'
,
'DELETE'
][
index
];
throw
Exception
(
'Could not launch
$url
'
);
}
}
}
/// 日志打印
/// 跳转 App Store 详情
_printLog
(
Response
?
response
)
{
void
jumpAppStore
(
String
id
)
async
{
var
responseData
=
response
?.
data
;
String
url
=
"https://apps.apple.com/cn/app/id
$id
"
;
var
requestOptions
=
response
?.
requestOptions
;
var
headers
=
response
?.
headers
;
final
uri
=
Uri
.
parse
(
url
);
debugPrint
(
"========== 网络请求响应 ==========
\n
"
if
(
await
canLaunchUrl
(
uri
))
{
"statusCode:
${response?.statusCode}
\n
"
await
launchUrl
(
"statusMessage:
${response?.statusMessage}
\n
"
uri
,
"method:
${requestOptions?.method}
\n
"
mode:
LaunchMode
.
externalApplication
,
"path:
${requestOptions?.path}
\n
"
);
"headers:
${headers?.map}
\n\n
"
return
;
"queryParameters:
${requestOptions?.queryParameters}
\n
"
}
"data:
${requestOptions?.data}
\n
"
"responseData:
$responseData
\n
"
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论