From 2eac3ee478f20f3432b1fbe6a5701a8298245d7c Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Tue, 9 Jul 2024 10:11:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=8D=8E=E4=B8=BA?= =?UTF-8?q?=E6=8B=92=E5=AE=A1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mine/addLock/addLock/addLock_logic.dart | 9 +- .../addLock/nearbyLock/nearbyLock_logic.dart | 116 +++++++++--------- .../addLock/nearbyLock/nearbyLock_page.dart | 1 - lib/widget/permission/permission_dialog.dart | 1 - 4 files changed, 62 insertions(+), 65 deletions(-) diff --git a/lib/mine/addLock/addLock/addLock_logic.dart b/lib/mine/addLock/addLock/addLock_logic.dart index 6a8f6d71..e36079bf 100755 --- a/lib/mine/addLock/addLock/addLock_logic.dart +++ b/lib/mine/addLock/addLock/addLock_logic.dart @@ -7,22 +7,19 @@ import 'package:star_lock/mine/addLock/addLock/addLock_state.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/widget/permission/permission_dialog.dart'; - class AddLockLogic extends BaseGetXController { final AddLockState state = AddLockState(); - //跳转到附近的锁页面先判断权限 Future getNearByLimits() async { if (!Platform.isIOS) { - bool bluetoothRequest = await PermissionDialog.requestBluetooth(); - bool locationRequest = await PermissionDialog.request(Permission.location); + final bool locationRequest = await PermissionDialog.request(Permission.location); + final bool bluetoothRequest = await PermissionDialog.requestBluetooth(); if (!bluetoothRequest || !locationRequest) { return; } } + Get.toNamed(Routers.nearbyLockPage); } - - } diff --git a/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart b/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart index 751c0e9c..2477cb87 100755 --- a/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart +++ b/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart @@ -1,4 +1,3 @@ - import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -9,6 +8,7 @@ import 'package:date_format/date_format.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/blue/io_protocol/io_getPrivateKey.dart'; import 'package:star_lock/blue/io_protocol/io_getPublicKey.dart'; import 'package:star_lock/blue/io_protocol/io_otaUpgrade.dart'; @@ -45,15 +45,8 @@ class NearbyLockLogic extends BaseGetXController { // 点击连接设备 void connect(String deviceName) { showTitleEasyLoading('获取锁信息 1/3'); - // if(state.sureBtnState.value == 1){ - // return; - // } - // state.sureBtnState.value = 1; - - // showEasyLoading(); showBlueConnetctToastTimer(action: () { dismissEasyLoading(); - // state.sureBtnState.value = 0; }); BlueManage().blueSendData(deviceName, (BluetoothConnectionState state) async { @@ -71,7 +64,7 @@ class NearbyLockLogic extends BaseGetXController { _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) { if (reply is GetPublicKeyReply) { - _replyGetPublicKey(reply); + _replyGetPublicKey(reply); } if (reply is GetPrivateKeyReply) { @@ -103,8 +96,6 @@ class NearbyLockLogic extends BaseGetXController { } Future _replyGetPublicKey(Reply reply) async { - // dismissEasyLoading(); - // 获取公钥 switch (reply.status) { case 0x00: @@ -127,7 +118,6 @@ class NearbyLockLogic extends BaseGetXController { needAuthor: 1); break; default: - // state.sureBtnState.value = 0; AppLog.log('获取公钥失败'); break; } @@ -142,7 +132,8 @@ class NearbyLockLogic extends BaseGetXController { // 私钥 final List privateKey = reply.data.sublist(0, 16); - final List savePrivateKeyList = changeIntListToStringList(privateKey); + final List savePrivateKeyList = + changeIntListToStringList(privateKey); Storage.setStringList(saveBluePrivateKey, savePrivateKeyList); // signKey @@ -160,7 +151,6 @@ class NearbyLockLogic extends BaseGetXController { _getStarLockStatus(); break; default: - // state.sureBtnState.value = 0; break; } } @@ -170,7 +160,7 @@ class NearbyLockLogic extends BaseGetXController { final int status = reply.data[2]; switch (status) { case 0x00: - //成功 + //成功 AppLog.log('获取锁状态成功'); // 厂商名称 int index = 3; @@ -196,14 +186,14 @@ class NearbyLockLogic extends BaseGetXController { AppLog.log('产品名称 mmodelStr:$modelStr'); // 软件版本 - final List fwVersion = reply.data.sublist(index, index+20); + final List fwVersion = reply.data.sublist(index, index + 20); final String fwVersionStr = utf8String(fwVersion); state.lockInfo['fwVersion'] = fwVersionStr; index = index + 20; AppLog.log('软件版本 fwVersionStr:$fwVersionStr'); // 硬件版本 - final List hwVersion = reply.data.sublist(index, index+20); + final List hwVersion = reply.data.sublist(index, index + 20); final String hwVersionStr = utf8String(hwVersion); state.lockInfo['hwVersion'] = hwVersionStr; index = index + 20; @@ -245,16 +235,18 @@ class NearbyLockLogic extends BaseGetXController { // 重置次数 final List restoreCounter = reply.data.sublist(index, index + 2); - state.lockInfo['restoreCount'] = restoreCounter[0] * 256 + restoreCounter[1]; + state.lockInfo['restoreCount'] = + restoreCounter[0] * 256 + restoreCounter[1]; index = index + 2; - AppLog.log('重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}'); + AppLog.log( + '重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}'); // 重置时间 final List restoreDate = reply.data.sublist(index, index + 4); final int restoreDateValue = (0xff & restoreDate[0]) << 24 | - (0xff & restoreDate[1]) << 16 | - (0xff & restoreDate[2]) << 8 | - (0xFF & restoreDate[3]); + (0xff & restoreDate[1]) << 16 | + (0xff & restoreDate[2]) << 8 | + (0xFF & restoreDate[3]); // String restoreDateStr = DateTool().dateToYMDHNSString(restoreDateValue.toString()); state.lockInfo['restoreDate'] = restoreDateValue * 1000; index = index + 4; @@ -270,9 +262,9 @@ class NearbyLockLogic extends BaseGetXController { // 有效时间 final List indate = reply.data.sublist(index, index + 4); final int indateValue = (0xff & indate[0]) << 24 | - (0xff & indate[1]) << 16 | - (0xff & indate[2]) << 8 | - (0xFF & indate[3]); + (0xff & indate[1]) << 16 | + (0xff & indate[2]) << 8 | + (0xFF & indate[3]); // String indateStr = DateTool().dateToYMDHNSString("$indateValue"); state.lockInfo['indate'] = indateValue * 1000; index = index + 4; @@ -286,7 +278,8 @@ class NearbyLockLogic extends BaseGetXController { AppLog.log('mac地址 macAddressStr:$macAddressStr'); //时区偏移 - state.lockInfo['timezoneOffset'] = DateTime.now().timeZoneOffset.inSeconds; + state.lockInfo['timezoneOffset'] = + DateTime.now().timeZoneOffset.inSeconds; // 锁特征值字符串长度 final int featureValueLength = reply.data[index]; @@ -300,7 +293,8 @@ class NearbyLockLogic extends BaseGetXController { showToast('锁数据异常,请重试'); return; } - final List featureValue = reply.data.sublist(index, index + featureValueLength); + final List featureValue = + reply.data.sublist(index, index + featureValueLength); final String featureValueStr = asciiString(featureValue); state.featureValue = featureValueStr; // List allFeatureValueTwoList = charListChangeIntList(featureValue); @@ -319,7 +313,8 @@ class NearbyLockLogic extends BaseGetXController { showToast('锁数据异常,请重试'); return; } - final List featureEnVal = reply.data.sublist(index, index + featureEnValLength); + final List featureEnVal = + reply.data.sublist(index, index + featureEnValLength); final String featureEnValStr = asciiString(featureEnVal); state.featureSettingValue = featureEnValStr; // List allFeatureEnValTwoList = charListChangeIntList(featureEnVal); @@ -344,14 +339,11 @@ class NearbyLockLogic extends BaseGetXController { break; case 0x06: - //无权限 - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); - // IoSenderManage.senderGetLockStatu( - // lockID:BlueManage().connectDeviceName, - // userID:await Storage.getUid(), - // privateKey:getPrivateKeyList, - // ); + //无权限 + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); IoSenderManage.senderGetStarLockStatuInfo( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), @@ -362,8 +354,7 @@ class NearbyLockLogic extends BaseGetXController { ); break; default: - //失败 - // state.sureBtnState.value = 0; + //失败 break; } } @@ -376,12 +367,16 @@ class NearbyLockLogic extends BaseGetXController { // dismissEasyLoading(); AppLog.log('开始获取锁状态'); - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); final List getPrivateKeyList = changeStringListToIntList(privateKey!); - - final String getUTCDate = formatDate(DateTime.fromMillisecondsSinceEpoch(state.serverTime*1000), [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn, ':', ss]); - final String getLocalDate = formatDate(DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000), [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn, ':', ss]); + final String getUTCDate = formatDate( + DateTime.fromMillisecondsSinceEpoch(state.serverTime * 1000), + [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn, ':', ss]); + final String getLocalDate = formatDate( + DateTime.fromMillisecondsSinceEpoch(getLocalTime() * 1000), + [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn, ':', ss]); AppLog.log('state.serverTime:${state.serverTime} getUTCDate:$getUTCDate ' 'getLocalTime:${getLocalTime()} getLocalDate:$getLocalDate ' @@ -394,10 +389,6 @@ class NearbyLockLogic extends BaseGetXController { isBeforeAddUser: true, privateKey: getPrivateKeyList, ); - // } else if (state == BluetoothConnectionState.disconnected) { - // dismissEasyLoading(); - // } - // }, isAddEquipment: true); } void startScanBlueList() { @@ -490,7 +481,7 @@ class NearbyLockLogic extends BaseGetXController { ).packageData()); } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {} - },isAddEquipment: true); + }, isAddEquipment: true); } //循环传输升级固件包 @@ -536,7 +527,7 @@ class NearbyLockLogic extends BaseGetXController { logic: this, ), barrierDismissible: false) - .then((value) => state.oTAProgressDialog = false); + .then((dynamic value) => state.oTAProgressDialog = false); } //清楚 ata 安装文件 @@ -632,9 +623,10 @@ class NearbyLockLogic extends BaseGetXController { } // 从服务器获取锁的时间 开锁时传入 - Future getServerDatetime() async{ - final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading:false); - if(entity.errorCode!.codeIsSuccessful){ + Future getServerDatetime() async { + final GetServerDatetimeEntity entity = + await ApiRepository.to.getServerDatetimeData(isUnShowLoading: false); + if (entity.errorCode!.codeIsSuccessful) { state.serverTime = entity.data!.date! ~/ 1000; if (state.otaState.value) { @@ -642,12 +634,10 @@ class NearbyLockLogic extends BaseGetXController { } else { connect(state.selectLockName.value); } - // state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000; - // AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}"); } } - int getLocalTime(){ + int getLocalTime() { final DateTime now = DateTime.now(); final Duration timeZoneOffset = now.timeZoneOffset; AppLog.log('timeZoneOffset.inSeconds:$timeZoneOffset.inSeconds'); @@ -657,9 +647,7 @@ class NearbyLockLogic extends BaseGetXController { @override void onReady() { super.onReady(); - _initReplySubscription(); - state.ifCurrentScreen.value = true; - startScanBlueList(); + getNearByLimits(); } @override @@ -672,4 +660,18 @@ class NearbyLockLogic extends BaseGetXController { super.onClose(); _replySubscription?.cancel(); } + + Future getNearByLimits() async { + if (!Platform.isIOS) { + final bool bluetoothRequest = await PermissionDialog.requestBluetooth(); + final bool locationRequest = + await PermissionDialog.request(Permission.location); + if (!bluetoothRequest || !locationRequest) { + return; + } + } + _initReplySubscription(); + state.ifCurrentScreen.value = true; + startScanBlueList(); + } } diff --git a/lib/mine/addLock/nearbyLock/nearbyLock_page.dart b/lib/mine/addLock/nearbyLock/nearbyLock_page.dart index d891b53a..25af5c88 100755 --- a/lib/mine/addLock/nearbyLock/nearbyLock_page.dart +++ b/lib/mine/addLock/nearbyLock/nearbyLock_page.dart @@ -6,7 +6,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/flavors.dart'; import '../../../app_settings/app_colors.dart'; -import '../../../blue/blue_manage.dart'; import '../../../tools/appRouteObserver.dart'; import '../../../tools/titleAppBar.dart'; import '../../../translations/trans_lib.dart'; diff --git a/lib/widget/permission/permission_dialog.dart b/lib/widget/permission/permission_dialog.dart index 50d7fab2..2a01642b 100755 --- a/lib/widget/permission/permission_dialog.dart +++ b/lib/widget/permission/permission_dialog.dart @@ -3,7 +3,6 @@ import 'package:get/get.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/app_settings/app_settings.dart'; import 'package:star_lock/tools/storage.dart'; -import 'package:star_lock/translations/trans_lib.dart'; class PermissionDialog { static Map titles = {