fix: 修复固件升级相关逻辑
This commit is contained in:
parent
51e8ecce4d
commit
b49a904999
@ -1,23 +0,0 @@
|
||||
import 'dart:io';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:star_lock/mine/addLock/nearbyLock/nearbyLock_logic.dart';
|
||||
import 'package:star_lock/tools/baseGetXController.dart';
|
||||
import 'package:star_lock/widget/permission/permission_dialog.dart';
|
||||
|
||||
class LockAddFaqLogic extends BaseGetXController {
|
||||
// 开始OTA升级
|
||||
void startOtaUpgrade() async {
|
||||
// 检查存储权限
|
||||
if (!Platform.isIOS) {
|
||||
final bool storageRequest = await PermissionDialog.requestStorage();
|
||||
if (!storageRequest) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建升级逻辑实例并开始升级
|
||||
final NearbyLockLogic upgradeLogic = NearbyLockLogic();
|
||||
upgradeLogic.otaUpdate();
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/mine/addLock/lockAddFaq/lockAddFaq_logic.dart';
|
||||
|
||||
import '../../../app_settings/app_colors.dart';
|
||||
import '../../../tools/titleAppBar.dart';
|
||||
@ -14,8 +13,6 @@ class LockAddFaqPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LockAddFaqPageState extends State<LockAddFaqPage> {
|
||||
final LockAddFaqLogic logic = Get.put(LockAddFaqLogic());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -71,7 +68,7 @@ class _LockAddFaqPageState extends State<LockAddFaqPage> {
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.symmetric(horizontal: 20.w),
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: logic.startOtaUpgrade,
|
||||
onPressed: Get.back,
|
||||
icon: const Icon(Icons.system_update_alt, color: Colors.white),
|
||||
label: Text(
|
||||
'尝试升级固件'.tr,
|
||||
|
||||
@ -56,6 +56,7 @@ class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
|
||||
body: Stack(
|
||||
children: [
|
||||
Obx(listView),
|
||||
// 左下角:找不到锁?点此查看
|
||||
Positioned(
|
||||
left: 16.w,
|
||||
bottom: 64.h,
|
||||
@ -103,6 +104,26 @@ class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
|
||||
),
|
||||
),
|
||||
),
|
||||
// 右下角:无法连接?尝试升级
|
||||
Positioned(
|
||||
right: 16.w,
|
||||
bottom: 64.h,
|
||||
child: Obx(() => TextButton(
|
||||
onPressed: () async {
|
||||
bool skip = false;
|
||||
if (!state.otaState.value) {
|
||||
skip = await Get.dialog(
|
||||
const _TipDialog(),
|
||||
);
|
||||
}
|
||||
state.otaState.value = skip;
|
||||
},
|
||||
child: Text(
|
||||
state.otaState.value ? '点击返回设备配对'.tr : '尝试升级'.tr,
|
||||
style: TextStyle(fontSize: 22.sp),
|
||||
),
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -133,7 +154,7 @@ class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
|
||||
},
|
||||
),
|
||||
),
|
||||
// 移除了原有的"无法连接?尝试升级"按钮
|
||||
// 移除底部的升级按钮,因为已经移到右下角了
|
||||
],
|
||||
);
|
||||
}
|
||||
@ -199,7 +220,9 @@ class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
|
||||
),
|
||||
Expanded(child: SizedBox(width: 20.w)),
|
||||
Image.asset(
|
||||
'images/main/icon_main_addLock.png',
|
||||
state.otaState.value
|
||||
? 'images/ota_upgrade_icon.png'
|
||||
: 'images/main/icon_main_addLock.png',
|
||||
width: 36.w,
|
||||
height: 36.w,
|
||||
color: AppColors.mainColor,
|
||||
@ -256,8 +279,97 @@ class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
|
||||
@override
|
||||
void didPushNext() {
|
||||
super.didPushNext();
|
||||
state.ifCurrentScreen.value = false;
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
logic.stopScanBlueList();
|
||||
if (!logic.state.otaState.value) {
|
||||
state.ifCurrentScreen.value = false;
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
logic.stopScanBlueList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _TipDialog extends StatelessWidget {
|
||||
const _TipDialog({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: Text(
|
||||
'固件升级提示'.tr,
|
||||
),
|
||||
content: Text('请先获取固件文件到手机本地,再选择升级'.tr),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: Get.back,
|
||||
child: Text(
|
||||
'取消'.tr,
|
||||
style: TextStyle(fontSize: 22.sp, color: AppColors.blackColor),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Get.back(result: true);
|
||||
},
|
||||
child: Text(
|
||||
'确定'.tr,
|
||||
style: TextStyle(fontSize: 22.sp, color: AppColors.blackColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class OTAProgressDialog extends StatelessWidget {
|
||||
NearbyLockLogic logic;
|
||||
|
||||
OTAProgressDialog({required this.logic, Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(() {
|
||||
return CupertinoAlertDialog(
|
||||
title: Text(
|
||||
'固件升级中'.tr,
|
||||
),
|
||||
content: Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 20.h, bottom: 10.h),
|
||||
child: Text(
|
||||
'传输期间请勿离开当前页面'.tr,
|
||||
style: TextStyle(fontSize: 20.sp, color: AppColors.blackColor),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'传输中'.tr,
|
||||
style: TextStyle(fontSize: 18.sp, color: AppColors.mainColor),
|
||||
),
|
||||
SizedBox(
|
||||
width: 15.w,
|
||||
),
|
||||
Expanded(
|
||||
child: LinearProgressIndicator(
|
||||
value: logic.state.otaProgress.value,
|
||||
color: AppColors.mainColor,
|
||||
)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
logic.closeOTADAta();
|
||||
},
|
||||
child: Text(
|
||||
'取消升级'.tr,
|
||||
style: TextStyle(fontSize: 22.sp, color: AppColors.blackColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user