mcy_new #1
|
|
@ -44,10 +44,13 @@ class AppVersion extends Object {
|
||||||
this.appFileUrl,
|
this.appFileUrl,
|
||||||
this.description,
|
this.description,
|
||||||
) {
|
) {
|
||||||
if (appFileUrl != null) appFileUrl = RequestConfig.imgUrl + appFileUrl!;
|
if (appFileUrl != null && ftuType != 2) {
|
||||||
|
appFileUrl = RequestConfig.imgUrl + appFileUrl!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
factory AppVersion.fromJson(Map<String, dynamic> srcJson) => _$AppVersionFromJson(srcJson);
|
factory AppVersion.fromJson(Map<String, dynamic> srcJson) =>
|
||||||
|
_$AppVersionFromJson(srcJson);
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => _$AppVersionToJson(this);
|
Map<String, dynamic> toJson() => _$AppVersionToJson(this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ import 'upgradeLogic.dart';
|
||||||
|
|
||||||
class DownloadApk {
|
class DownloadApk {
|
||||||
/// 下载安卓更新包
|
/// 下载安卓更新包
|
||||||
static Future<File?> _downloadAndroid(context, UpdateAppEvent event, UpgradeLogic logic) async {
|
static Future<File?> _downloadAndroid(
|
||||||
|
context, UpdateAppEvent event, UpgradeLogic logic) async {
|
||||||
/// 创建存储文件
|
/// 创建存储文件
|
||||||
Directory? storageDir = await getExternalStorageDirectory();
|
Directory? storageDir = await getExternalStorageDirectory();
|
||||||
final storagePath = storageDir?.path ?? '/';
|
final storagePath = storageDir?.path ?? '/';
|
||||||
|
|
@ -47,10 +48,12 @@ class DownloadApk {
|
||||||
print(e);
|
print(e);
|
||||||
// toPrint(val: e);
|
// toPrint(val: e);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 安装apk
|
// 安装apk
|
||||||
static Future<bool> installApk(context, UpdateAppEvent event, UpgradeLogic logic) async {
|
static Future<bool> installApk(
|
||||||
|
context, UpdateAppEvent event, UpgradeLogic logic) async {
|
||||||
try {
|
try {
|
||||||
logic.loadingApk.value = true;
|
logic.loadingApk.value = true;
|
||||||
File? _apkFile = await _downloadAndroid(context, event, logic);
|
File? _apkFile = await _downloadAndroid(context, event, logic);
|
||||||
|
|
@ -73,7 +76,9 @@ class DownloadApk {
|
||||||
actions: [
|
actions: [
|
||||||
MaterialButton(
|
MaterialButton(
|
||||||
color: Theme.of(context).primaryColor,
|
color: Theme.of(context).primaryColor,
|
||||||
child: const Text("我已知晓", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
child: const Text("我已知晓",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white, fontWeight: FontWeight.bold)),
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
@ -87,9 +92,12 @@ class DownloadApk {
|
||||||
// 其他方式下载
|
// 其他方式下载
|
||||||
// await SystemNavigator.pop(); // 退出APP
|
// await SystemNavigator.pop(); // 退出APP
|
||||||
var options = ['应用市场更新APP', '浏览器下载并安装APP'];
|
var options = ['应用市场更新APP', '浏览器下载并安装APP'];
|
||||||
var uri = Uri.parse('market://details?id=${event.packageName}'); // 应用市场URI
|
var uri =
|
||||||
if (!await canLaunchUrl(uri)) options.removeAt(0); // 如果不能打开应用市场 就屏蔽掉 这个安装方式
|
Uri.parse('market://details?id=${event.packageName}'); // 应用市场URI
|
||||||
String? option = await UpgradePermission.showCustomModalBottomSheet(context, options);
|
if (!await canLaunchUrl(uri))
|
||||||
|
options.removeAt(0); // 如果不能打开应用市场 就屏蔽掉 这个安装方式
|
||||||
|
String? option = await UpgradePermission.showCustomModalBottomSheet(
|
||||||
|
context, options);
|
||||||
if (option == '应用市场更新APP') await launchUrl(uri);
|
if (option == '应用市场更新APP') await launchUrl(uri);
|
||||||
if (option == '浏览器下载并安装APP') await launchUrl(Uri.parse(event.link));
|
if (option == '浏览器下载并安装APP') await launchUrl(Uri.parse(event.link));
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|
@ -107,7 +115,8 @@ class DownloadApk {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 展示下载进度
|
/// 展示下载进度
|
||||||
static void showDownloadProgress(context, num received, num total, UpgradeLogic logic) {
|
static void showDownloadProgress(
|
||||||
|
context, num received, num total, UpgradeLogic logic) {
|
||||||
if (total != -1) {
|
if (total != -1) {
|
||||||
double progress = double.parse((received / total).toStringAsFixed(2));
|
double progress = double.parse((received / total).toStringAsFixed(2));
|
||||||
// debugPrint('下载进度$progress');
|
// debugPrint('下载进度$progress');
|
||||||
|
|
@ -122,7 +131,8 @@ class RestartWidget extends StatefulWidget {
|
||||||
const RestartWidget({super.key, required this.child});
|
const RestartWidget({super.key, required this.child});
|
||||||
|
|
||||||
static restartApp(BuildContext context) {
|
static restartApp(BuildContext context) {
|
||||||
final _RestartWidgetState? state = context.findAncestorStateOfType<_RestartWidgetState>();
|
final _RestartWidgetState? state =
|
||||||
|
context.findAncestorStateOfType<_RestartWidgetState>();
|
||||||
state?.restartApp();
|
state?.restartApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
* @LastEditors: Please set LastEditors
|
* @LastEditors: Please set LastEditors
|
||||||
* @LastEditTime: 2021-01-12 15:08:43
|
* @LastEditTime: 2021-01-12 15:08:43
|
||||||
*/
|
*/
|
||||||
import 'package:auto_updater/auto_updater.dart';
|
|
||||||
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
|
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:making_school_asignment_app/common/utils/app_upgrade/DownloadApk.dart';
|
import 'package:making_school_asignment_app/common/utils/app_upgrade/DownloadApk.dart';
|
||||||
|
|
@ -34,7 +33,8 @@ class UpdateDialog extends Dialog {
|
||||||
final UpdateAppEvent updateAppEvent;
|
final UpdateAppEvent updateAppEvent;
|
||||||
final String deviceInfo;
|
final String deviceInfo;
|
||||||
|
|
||||||
const UpdateDialog({super.key, required this.updateAppEvent, required this.deviceInfo});
|
const UpdateDialog(
|
||||||
|
{super.key, required this.updateAppEvent, required this.deviceInfo});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
@ -72,11 +72,17 @@ class UpdateDialog extends Dialog {
|
||||||
HtmlWidget(
|
HtmlWidget(
|
||||||
updateAppEvent.description,
|
updateAppEvent.description,
|
||||||
customStylesBuilder: (element) {
|
customStylesBuilder: (element) {
|
||||||
return {'color': '#666666', 'font-weight': 'normal', 'text-decoration': 'none'};
|
return {
|
||||||
|
'color': '#666666',
|
||||||
|
'font-weight': 'normal',
|
||||||
|
'text-decoration': 'none'
|
||||||
|
};
|
||||||
},
|
},
|
||||||
onLoadingBuilder: (context, element, loadingProgress) => const CircularProgressIndicator(),
|
onLoadingBuilder: (context, element, loadingProgress) =>
|
||||||
|
const CircularProgressIndicator(),
|
||||||
renderMode: RenderMode.column,
|
renderMode: RenderMode.column,
|
||||||
textStyle: TextStyle(fontSize: 14.sp, color: Colors.black87),
|
textStyle:
|
||||||
|
TextStyle(fontSize: 14.sp, color: Colors.black87),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -97,7 +103,9 @@ class UpdateDialog extends Dialog {
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: () async => false,
|
onWillPop: () async => false,
|
||||||
child: UpdateDialog(updateAppEvent: updateAppEvent, deviceInfo: updateAppEvent.deviceInfo),
|
child: UpdateDialog(
|
||||||
|
updateAppEvent: updateAppEvent,
|
||||||
|
deviceInfo: updateAppEvent.deviceInfo),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -136,7 +144,10 @@ class DownloadProgress extends StatelessWidget {
|
||||||
Container(
|
Container(
|
||||||
height: 6.h,
|
height: 6.h,
|
||||||
),
|
),
|
||||||
quickText('更新中...', size: 12.sp, fontWeight: FontWeight.w500, color: const Color.fromRGBO(90, 90, 90, 1))
|
quickText('更新中...',
|
||||||
|
size: 12.sp,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: const Color.fromRGBO(90, 90, 90, 1))
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -152,7 +163,7 @@ class DownloadButton extends StatelessWidget {
|
||||||
|
|
||||||
// 打开浏览器或者对应的对应市场进行下载
|
// 打开浏览器或者对应的对应市场进行下载
|
||||||
Future<bool> toLaunch(UpdateAppEvent data) async {
|
Future<bool> toLaunch(UpdateAppEvent data) async {
|
||||||
var uri = Uri.parse('market://details?id=com.yuanxuan.making_school_asignment_app');
|
var uri = Uri.parse('market://details?id=${updateAppEvent.packageName}');
|
||||||
if (await canLaunchUrl(uri)) {
|
if (await canLaunchUrl(uri)) {
|
||||||
// 跳进对应的应用市场进行更新操作
|
// 跳进对应的应用市场进行更新操作
|
||||||
return await launchUrl(uri);
|
return await launchUrl(uri);
|
||||||
|
|
@ -181,15 +192,20 @@ class DownloadButton extends StatelessWidget {
|
||||||
width: 245.w,
|
width: 245.w,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.all(Radius.circular(42.h)),
|
borderRadius: BorderRadius.all(Radius.circular(42.h)),
|
||||||
gradient: LinearGradient(colors: [primaryColor, primaryColor.withOpacity(0.7)]),
|
gradient: LinearGradient(
|
||||||
|
colors: [primaryColor, primaryColor.withOpacity(0.7)]),
|
||||||
),
|
),
|
||||||
child: MaterialButton(
|
child: MaterialButton(
|
||||||
onPressed: () => easyThrottle('DownloadButton_App_Upgrade', duration: const Duration(milliseconds: 1000), () async {
|
onPressed: () => easyThrottle('DownloadButton_App_Upgrade',
|
||||||
if (deviceInfo == "android" && updateAppEvent.equipment == Equipment.android) {
|
duration: const Duration(milliseconds: 1000), () async {
|
||||||
|
if (deviceInfo == "android" &&
|
||||||
|
updateAppEvent.equipment == Equipment.android) {
|
||||||
// 权限检查 判断是否有读写内存的权限
|
// 权限检查 判断是否有读写内存的权限
|
||||||
bool flag = await UpgradePermission(updateAppEvent.deviceInfo).checkPermission(context, updateAppEvent);
|
bool flag = await UpgradePermission(updateAppEvent.deviceInfo)
|
||||||
|
.checkPermission(context, updateAppEvent);
|
||||||
if (flag) {
|
if (flag) {
|
||||||
flag = await DownloadApk.installApk(context, updateAppEvent, logic);
|
flag = await DownloadApk.installApk(
|
||||||
|
context, updateAppEvent, logic);
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
print('执行到了重置更新按钮的地方....');
|
print('执行到了重置更新按钮的地方....');
|
||||||
logic.downloadRatio.value = 0.0; // 更新失败重置 更新按钮
|
logic.downloadRatio.value = 0.0; // 更新失败重置 更新按钮
|
||||||
|
|
@ -201,8 +217,10 @@ class DownloadButton extends StatelessWidget {
|
||||||
}
|
}
|
||||||
// await FlutterClipboard.copy(updateAppEvent.link);
|
// await FlutterClipboard.copy(updateAppEvent.link);
|
||||||
// setTimeOut(1000, () => ToastUtils.showInfo('下载链接已经复制到设备,可前往浏览器下载安装'));
|
// setTimeOut(1000, () => ToastUtils.showInfo('下载链接已经复制到设备,可前往浏览器下载安装'));
|
||||||
} else if (deviceInfo == "ios" && updateAppEvent.equipment == Equipment.ios) {
|
} else if (deviceInfo == "ios" &&
|
||||||
|
updateAppEvent.equipment == Equipment.ios) {
|
||||||
try {
|
try {
|
||||||
|
print(updateAppEvent.link);
|
||||||
await launchUrlString(updateAppEvent.link);
|
await launchUrlString(updateAppEvent.link);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('进来更新报错$e');
|
print('进来更新报错$e');
|
||||||
|
|
@ -214,7 +232,8 @@ class DownloadButton extends StatelessWidget {
|
||||||
// await autoUpdater.setScheduledCheckInterval(0);
|
// await autoUpdater.setScheduledCheckInterval(0);
|
||||||
// }
|
// }
|
||||||
}),
|
}),
|
||||||
child: quickText(!logic.loadingApk.value ? '立即体验' : '正在下载...', size: 16.sp, color: Colors.white, fontWeight: FontWeight.w500),
|
child: quickText(!logic.loadingApk.value ? '立即体验' : '正在下载...',
|
||||||
|
size: 16.sp, color: Colors.white, fontWeight: FontWeight.w500),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ class UpgradeLogic extends GetxController with RequestToolMixin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppVersion? result = await getClient().getLastAppVersion('making_school_asignment_app', deviceType);
|
AppVersion? result = await getClient()
|
||||||
|
.getLastAppVersion('making_school_asignment_app', deviceType);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
//获取当前版本
|
//获取当前版本
|
||||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||||
|
|
@ -60,8 +61,11 @@ class UpgradeLogic extends GetxController with RequestToolMixin {
|
||||||
'systemType': deviceType,
|
'systemType': deviceType,
|
||||||
'description': result.description ?? 'APP新版本更新'
|
'description': result.description ?? 'APP新版本更新'
|
||||||
};
|
};
|
||||||
UpdateAppEvent updateAppEvent = UpdateAppEvent.fromJson(json, localVersion, deviceInfo, appName, packageName, typeName: 'systemType');
|
UpdateAppEvent updateAppEvent = UpdateAppEvent.fromJson(
|
||||||
|
json, localVersion, deviceInfo, appName, packageName,
|
||||||
|
typeName: 'systemType');
|
||||||
if (updateAppEvent.upgrade) {
|
if (updateAppEvent.upgrade) {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
|
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
|
||||||
AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
|
AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
|
||||||
Permission storagePermission;
|
Permission storagePermission;
|
||||||
|
|
@ -70,13 +74,18 @@ class UpgradeLogic extends GetxController with RequestToolMixin {
|
||||||
} else {
|
} else {
|
||||||
storagePermission = Permission.storage;
|
storagePermission = Permission.storage;
|
||||||
}
|
}
|
||||||
PermissionDescribeUtil.instance.toLaunchPermissionRequest(
|
await PermissionDescribeUtil.instance.toLaunchPermissionRequest(
|
||||||
context,
|
Get.context ?? context,
|
||||||
title: '储存权限请求',
|
title: '储存权限请求',
|
||||||
describe: "为了提供更好的服务,需要获取到存储权限用于保存APP升级文件APK,进行升级",
|
describe: "为了提供更好的服务,需要获取到存储权限用于保存APP升级文件APK,进行升级",
|
||||||
permissions: [storagePermission],
|
permissions: [storagePermission],
|
||||||
);
|
);
|
||||||
await UpdateDialog.showUpdateDialog(context, updateAppEvent);
|
}
|
||||||
|
|
||||||
|
await UpdateDialog.showUpdateDialog(
|
||||||
|
Get.context ?? context,
|
||||||
|
updateAppEvent,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,18 @@ class PermissionDescribePage extends StatefulWidget {
|
||||||
final String describe;
|
final String describe;
|
||||||
final List<Permission> permissions;
|
final List<Permission> permissions;
|
||||||
|
|
||||||
const PermissionDescribePage({required this.title, required this.describe, required this.permissions, super.key});
|
const PermissionDescribePage(
|
||||||
|
{required this.title,
|
||||||
|
required this.describe,
|
||||||
|
required this.permissions,
|
||||||
|
super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<PermissionDescribePage> createState() => _PermissionDescribePageState();
|
State<PermissionDescribePage> createState() => _PermissionDescribePageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PermissionDescribePageState extends State<PermissionDescribePage> with WidgetsBindingObserver {
|
class _PermissionDescribePageState extends State<PermissionDescribePage>
|
||||||
|
with WidgetsBindingObserver {
|
||||||
Timer? _timerPermission;
|
Timer? _timerPermission;
|
||||||
bool theOpenAppSettings = false;
|
bool theOpenAppSettings = false;
|
||||||
int theExecutionFrequency = 0;
|
int theExecutionFrequency = 0;
|
||||||
|
|
@ -132,7 +137,9 @@ class _PermissionDescribePageState extends State<PermissionDescribePage> with Wi
|
||||||
|
|
||||||
/// 权限发起请求
|
/// 权限发起请求
|
||||||
/// @param List<Permission> permissions 权限集合
|
/// @param List<Permission> permissions 权限集合
|
||||||
Future<List<Permission>> getStoragePermission(BuildContext context, List<Permission> permissions, [int executionFrequency = 0]) async {
|
Future<List<Permission>> getStoragePermission(
|
||||||
|
BuildContext context, List<Permission> permissions,
|
||||||
|
[int executionFrequency = 0]) async {
|
||||||
Map<Permission, PermissionStatus> statusRes = await permissions.request();
|
Map<Permission, PermissionStatus> statusRes = await permissions.request();
|
||||||
|
|
||||||
List<Permission> permanentRefusal = []; // 永久拒绝
|
List<Permission> permanentRefusal = []; // 永久拒绝
|
||||||
|
|
@ -173,7 +180,8 @@ class _PermissionDescribePageState extends State<PermissionDescribePage> with Wi
|
||||||
executionFrequency++;
|
executionFrequency++;
|
||||||
}
|
}
|
||||||
if (executionFrequency <= 1) {
|
if (executionFrequency <= 1) {
|
||||||
var res = await getStoragePermission(context, [key], executionFrequency);
|
var res =
|
||||||
|
await getStoragePermission(context, [key], executionFrequency);
|
||||||
permanentRefusal.addAll(res);
|
permanentRefusal.addAll(res);
|
||||||
} else {
|
} else {
|
||||||
permanentRefusal.add(key);
|
permanentRefusal.add(key);
|
||||||
|
|
@ -231,12 +239,10 @@ class PermissionDescribeUtil {
|
||||||
|
|
||||||
PermissionDescribeUtil._internal();
|
PermissionDescribeUtil._internal();
|
||||||
|
|
||||||
static get instance {
|
static get instance => _instance ??= PermissionDescribeUtil._internal();
|
||||||
return _instance ??= PermissionDescribeUtil._internal();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 发起权限请求
|
/// 发起权限请求
|
||||||
void toLaunchPermissionRequest(
|
Future<void> toLaunchPermissionRequest(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required String title,
|
required String title,
|
||||||
required String describe,
|
required String describe,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue