fix:添加首次开锁清除蓝牙设备列表缓存,蓝牙操作添加缓存加快

This commit is contained in:
anfe 2024-05-14 18:07:58 +08:00
parent 6a83797003
commit 4a3d104a89
5 changed files with 79 additions and 63 deletions

View File

@ -125,8 +125,6 @@ PODS:
- Flutter - Flutter
- package_info_plus (0.4.5): - package_info_plus (0.4.5):
- Flutter - Flutter
- partial_media_permissions (0.0.1):
- Flutter
- path_provider_foundation (0.0.1): - path_provider_foundation (0.0.1):
- Flutter - Flutter
- FlutterMacOS - FlutterMacOS
@ -186,7 +184,6 @@ DEPENDENCIES:
- just_audio (from `.symlinks/plugins/just_audio/ios`) - just_audio (from `.symlinks/plugins/just_audio/ios`)
- network_info_plus (from `.symlinks/plugins/network_info_plus/ios`) - network_info_plus (from `.symlinks/plugins/network_info_plus/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- partial_media_permissions (from `.symlinks/plugins/partial_media_permissions/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
@ -277,8 +274,6 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/network_info_plus/ios" :path: ".symlinks/plugins/network_info_plus/ios"
package_info_plus: package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios" :path: ".symlinks/plugins/package_info_plus/ios"
partial_media_permissions:
:path: ".symlinks/plugins/partial_media_permissions/ios"
path_provider_foundation: path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin" :path: ".symlinks/plugins/path_provider_foundation/darwin"
permission_handler_apple: permission_handler_apple:
@ -327,7 +322,7 @@ SPEC CHECKSUMS:
flutter_native_contact_picker: bd430ba0fbf82768bb50c2c52a69a65759a8f907 flutter_native_contact_picker: bd430ba0fbf82768bb50c2c52a69a65759a8f907
flutter_pcm_sound: de0572ca4f99091cc2abfcc31601b8a4ddd33c0e flutter_pcm_sound: de0572ca4f99091cc2abfcc31601b8a4ddd33c0e
flutter_voice_processor: 2b89b93d69b02227ae3fd58589ee0bcfa3ca2a82 flutter_voice_processor: 2b89b93d69b02227ae3fd58589ee0bcfa3ca2a82
fluttertoast: 9f2f8e81bb5ce18facb9748d7855bf5a756fe3db fluttertoast: 31b00dabfa7fb7bacd9e7dbee580d7a2ff4bf265
fluwx: daa284756ce53442b3d0417ceeda66e981906811 fluwx: daa284756ce53442b3d0417ceeda66e981906811
google_maps_flutter_ios: d1318b4ff711612cab16862d7a87e31a7403d458 google_maps_flutter_ios: d1318b4ff711612cab16862d7a87e31a7403d458
GoogleMaps: 20d7b12be49a14287f797e88e0e31bc4156aaeb4 GoogleMaps: 20d7b12be49a14287f797e88e0e31bc4156aaeb4
@ -340,7 +335,6 @@ SPEC CHECKSUMS:
just_audio: baa7252489dbcf47a4c7cc9ca663e9661c99aafa just_audio: baa7252489dbcf47a4c7cc9ca663e9661c99aafa
network_info_plus: 6d0c3eb8367b8164fa3fb0c19875e3f59d49697f network_info_plus: 6d0c3eb8367b8164fa3fb0c19875e3f59d49697f
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
partial_media_permissions: 0fd34002b1dbfd5e8b4c60eb0d99e8e755a77f76
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
ReachabilitySwift: 2128f3a8c9107e1ad33574c6e58e8285d460b149 ReachabilitySwift: 2128f3a8c9107e1ad33574c6e58e8285d460b149
@ -357,4 +351,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 317f9473a5705c6fe4d79d95e81676f248048fdc PODFILE CHECKSUM: 317f9473a5705c6fe4d79d95e81676f248048fdc
COCOAPODS: 1.15.2 COCOAPODS: 1.14.3

View File

@ -282,14 +282,17 @@ class BlueManage {
} }
// String listStr = scanDevices // String listStr = scanDevices
// // .where((element) => // .where((element) =>
// // element.advertisementData.advName == 'TMH_dc8f928369ed') // element.advertisementData.advName == 'TMH_dc8f928369ed' ||
// element.device.platformName == 'TMH_dc8f928369ed')
// .map((e) => 'advName:${e.advertisementData.advName} ' // .map((e) => 'advName:${e.advertisementData.advName} '
// 'serviceUuids:${e.advertisementData.serviceUuids} ' // 'serviceUuids:${e.advertisementData.serviceUuids} '
// '是否被重置:${e.advertisementData.serviceUuids[0].toString()[31]}') // '是否被重置:${e.advertisementData.serviceUuids[0].toString()[31]}')
// .join(',') // .join(',')
// .toString(); // .toString();
// AppLog.log('--->扫描到的设备 ${listStr} '); // if (listStr.trim() != '') {
// AppLog.log('--->扫描到的设备 ${listStr} ');
// }
scanDevicesCallBack(scanDevices); scanDevicesCallBack(scanDevices);
// EventBusManager().eventBusFir(scanDevices); // EventBusManager().eventBusFir(scanDevices);
@ -354,9 +357,14 @@ class BlueManage {
{bool isAddEquipment = false}) async { {bool isAddEquipment = false}) async {
connectDeviceName = deviceName; connectDeviceName = deviceName;
List<ScanResult> devicesList = scanDevices; List<ScanResult> devicesList = scanDevices;
if (isAddEquipment == false) {
bool isExistDevice = scanDevices.any((element) =>
element.device.platformName == connectDeviceName ||
element.advertisementData.advName == connectDeviceName);
if (isAddEquipment == false || isExistDevice == false) {
//使 //使
startScan(10, (List<ScanResult> scanDevices) { startScanSingle(deviceName, 10, (List<ScanResult> scanDevices) {
_connectDevice(scanDevices, deviceName, connectStateCallBack, _connectDevice(scanDevices, deviceName, connectStateCallBack,
isAddEquipment: isAddEquipment); isAddEquipment: isAddEquipment);
}); });

View File

@ -4,6 +4,7 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_colors.dart'; import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/blue/blue_manage.dart';
import 'package:star_lock/main/lockMian/lockList/lockList_xhj_page.dart'; import 'package:star_lock/main/lockMian/lockList/lockList_xhj_page.dart';
import 'package:star_lock/tools/noData.dart'; import 'package:star_lock/tools/noData.dart';
import 'package:star_lock/tools/submitBtn.dart'; import 'package:star_lock/tools/submitBtn.dart';
@ -36,22 +37,21 @@ class _StarLockMainPageState extends State<StarLockMainPage> with BaseWidget {
final logic = Get.put(LockMainLogic()); final logic = Get.put(LockMainLogic());
final state = Get.find<LockMainLogic>().state; final state = Get.find<LockMainLogic>().state;
Future<void> getHttpData() async { Future<void> getHttpData({bool clearScanDevices = false}) async {
LockListInfoGroupEntity? lockListInfoGroupEntity = LockListInfoGroupEntity? lockListInfoGroupEntity =
await Storage.getLockMainListData(); await Storage.getLockMainListData();
if (lockListInfoGroupEntity != null) { if (lockListInfoGroupEntity != null) {
var localLockListInfoGroupEntity = lockListInfoGroupEntity; var localLockListInfoGroupEntity = lockListInfoGroupEntity;
logic.loadMainDataLogic(localLockListInfoGroupEntity).then((value) { await logic.loadMainDataLogic(localLockListInfoGroupEntity);
if (mounted) { }
setState(() {}); await logic.getStarLockInfo();
} await Future.delayed(const Duration(milliseconds: 200));
}); if (clearScanDevices) {
BlueManage().scanDevices.clear();
}
if (mounted) {
setState(() {});
} }
logic.getStarLockInfo().then((LockListInfoEntity value) {
if (mounted) {
setState(() {});
}
});
} }
@override @override
@ -237,7 +237,7 @@ class _StarLockMainPageState extends State<StarLockMainPage> with BaseWidget {
void _initLoadDataAction() { void _initLoadDataAction() {
_teamEvent = eventBus.on<RefreshLockListInfoDataEvent>().listen((event) { _teamEvent = eventBus.on<RefreshLockListInfoDataEvent>().listen((event) {
logic.pageNo = 1; logic.pageNo = 1;
getHttpData(); getHttpData(clearScanDevices: event.clearScanDevices);
}); });
} }

View File

@ -1,4 +1,3 @@
import 'dart:async'; import 'dart:async';
import 'dart:math'; import 'dart:math';
@ -31,8 +30,10 @@ class SaveLockLogic extends BaseGetXController {
// //
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) { _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((reply) {
if (reply is AddUserReply && state.ifCurrentScreen.value == true) { if (reply is AddUserReply && state.ifCurrentScreen.value == true) {
_replyAddUserKey(reply); _replyAddUserKey(reply);
} }
@ -81,19 +82,19 @@ class SaveLockLogic extends BaseGetXController {
startDate: DateTime.now().millisecondsSinceEpoch, startDate: DateTime.now().millisecondsSinceEpoch,
expireDate: 0x11223344, expireDate: 0x11223344,
useCountLimit: 0xFFFF, useCountLimit: 0xFFFF,
isRound:0, isRound: 0,
weekRound: 0, weekRound: 0,
startHour: 0, startHour: 0,
startMin: 0, startMin: 0,
endHour: 0, endHour: 0,
endMin: 0, endMin: 0,
role: 255, role: 255,
password: state.adminPassword, password: state.adminPassword,
needAuthor: 1, needAuthor: 1,
publicKey: publicKeyDataList, publicKey: publicKeyDataList,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
token: token, token: token,
isBeforeAddUser: true); isBeforeAddUser: true);
break; break;
default: default:
// loading // loading
@ -195,7 +196,7 @@ class SaveLockLogic extends BaseGetXController {
// //
Future<void> addUserConnectBlue() async { Future<void> addUserConnectBlue() async {
// //
if(state.sureBtnState.value == 1){ if (state.sureBtnState.value == 1) {
return; return;
} }
state.sureBtnState.value = 1; state.sureBtnState.value = 1;
@ -203,15 +204,16 @@ class SaveLockLogic extends BaseGetXController {
// showTitleEasyLoading("添加锁进行中 1/2"); // showTitleEasyLoading("添加锁进行中 1/2");
showEasyLoading(); showEasyLoading();
// //
showBlueConnetctToastTimer(action: (){ showBlueConnetctToastTimer(action: () {
dismissEasyLoading(); dismissEasyLoading();
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
if(state.ifCurrentScreen.value == true){ if (state.ifCurrentScreen.value == true) {
showBlueConnetctToast(); showBlueConnetctToast();
} }
}); });
BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { BlueManage().bludSendData(BlueManage().connectDeviceName,
if (deviceConnectionState == BluetoothConnectionState.connected){ (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
// //
var privateKey = await Storage.getStringList(saveBluePrivateKey); var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -226,33 +228,33 @@ class SaveLockLogic extends BaseGetXController {
} }
IoSenderManage.senderAddUser( IoSenderManage.senderAddUser(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
authUserID:await Storage.getUid(), authUserID: await Storage.getUid(),
keyID:"1", keyID: "1",
userID:await Storage.getUid(), userID: await Storage.getUid(),
openMode:1, openMode: 1,
keyType:1, keyType: 1,
startDate:DateTime.now().millisecondsSinceEpoch, startDate: DateTime.now().millisecondsSinceEpoch,
expireDate:0x11223344, expireDate: 0x11223344,
useCountLimit: 0xFFFF, useCountLimit: 0xFFFF,
isRound:0, isRound: 0,
weekRound: 0, weekRound: 0,
startHour: 0, startHour: 0,
startMin: 0, startMin: 0,
endHour: 0, endHour: 0,
endMin: 0, endMin: 0,
role:255, role: 255,
password:state.adminPassword, password: state.adminPassword,
needAuthor:1, needAuthor: 1,
publicKey:publicKeyDataList, publicKey: publicKeyDataList,
privateKey:getPrivateKeyList, privateKey: getPrivateKeyList,
token: getTokenList, token: getTokenList,
isBeforeAddUser: true isBeforeAddUser: true);
); } else if (deviceConnectionState ==
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) { BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
if(state.ifCurrentScreen.value == true){ if (state.ifCurrentScreen.value == true) {
showBlueConnetctToast(); showBlueConnetctToast();
} }
} }
@ -352,7 +354,7 @@ class SaveLockLogic extends BaseGetXController {
// }, isAddEquipment: true); // }, isAddEquipment: true);
// } // }
void bindBlueAdmin() async{ void bindBlueAdmin() async {
state.lockInfo["adminPwd"] = state.adminPassword; state.lockInfo["adminPwd"] = state.adminPassword;
var positionMap = {}; var positionMap = {};
@ -402,7 +404,7 @@ class SaveLockLogic extends BaseGetXController {
// BlueManage().disconnect(BlueManage().connectDeviceMacAddress); // BlueManage().disconnect(BlueManage().connectDeviceMacAddress);
// eventBus.fire(RefreshLockListInfoDataEvent()); // eventBus.fire(RefreshLockListInfoDataEvent());
// Get.close(state.isFromMap == 1 ? 5 : 6); // Get.close(state.isFromMap == 1 ? 5 : 6);
}else{ } else {
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
} }
} }
@ -457,8 +459,8 @@ class SaveLockLogic extends BaseGetXController {
// ); // );
// } // }
void backAction(){ void backAction() {
eventBus.fire(RefreshLockListInfoDataEvent()); eventBus.fire(RefreshLockListInfoDataEvent(clearScanDevices: true));
BlueManage().disconnect(); BlueManage().disconnect();
Get.close(state.isFromMap == 1 ? 5 : 6); Get.close(state.isFromMap == 1 ? 5 : 6);
} }
@ -475,7 +477,6 @@ class SaveLockLogic extends BaseGetXController {
void onInit() { void onInit() {
// TODO: implement onInit // TODO: implement onInit
super.onInit(); super.onInit();
} }
@override @override
@ -484,5 +485,4 @@ class SaveLockLogic extends BaseGetXController {
_replySubscription.cancel(); _replySubscription.cancel();
super.onClose(); super.onClose();
} }
} }

View File

@ -7,13 +7,17 @@ EventBus eventBus = EventBus();
/// ///
class RefreshLockListInfoDataEvent { class RefreshLockListInfoDataEvent {
RefreshLockListInfoDataEvent(); //
bool clearScanDevices;
RefreshLockListInfoDataEvent({this.clearScanDevices = false});
} }
/// ///
class LockAddUserSucceedEvent { class LockAddUserSucceedEvent {
int type; // 0 1token失效 int type; // 0 1token失效
List<int> dataList; List<int> dataList;
LockAddUserSucceedEvent(this.dataList, this.type); LockAddUserSucceedEvent(this.dataList, this.type);
} }
@ -40,6 +44,7 @@ class RefreshCheckInListEvent {
/// ///
class PassCurrentLockInformationEvent { class PassCurrentLockInformationEvent {
LockSetInfoData lockSetInfoData; LockSetInfoData lockSetInfoData;
PassCurrentLockInformationEvent(this.lockSetInfoData); PassCurrentLockInformationEvent(this.lockSetInfoData);
} }
@ -51,12 +56,14 @@ class OtherTypeRefreshListEvent {
/// number /// number
class ChickInAddStaffCardAndFingerprintBlockNumberEvent { class ChickInAddStaffCardAndFingerprintBlockNumberEvent {
String number; String number;
ChickInAddStaffCardAndFingerprintBlockNumberEvent(this.number); ChickInAddStaffCardAndFingerprintBlockNumberEvent(this.number);
} }
/// ///
class ChangeLanguageBlockLastLanguageEvent { class ChangeLanguageBlockLastLanguageEvent {
String languageTitle; String languageTitle;
ChangeLanguageBlockLastLanguageEvent(this.languageTitle); ChangeLanguageBlockLastLanguageEvent(this.languageTitle);
} }
@ -69,36 +76,42 @@ class LockGroupEditGroupLockRefreshEvent {
class LockSetChangeSetRefreshLockDetailWithType { class LockSetChangeSetRefreshLockDetailWithType {
int type; // 0 1 2 3 4 5 int type; // 0 1 2 3 4 5
String setResult; String setResult;
LockSetChangeSetRefreshLockDetailWithType(this.type, this.setResult); LockSetChangeSetRefreshLockDetailWithType(this.type, this.setResult);
} }
/// ///
class GetTVDataRefreshUI { class GetTVDataRefreshUI {
List<int> tvList; List<int> tvList;
GetTVDataRefreshUI(this.tvList); GetTVDataRefreshUI(this.tvList);
} }
/// UDP接收状态然后刷新界面 /// UDP接收状态然后刷新界面
class GetUDPStatusRefreshUI { class GetUDPStatusRefreshUI {
int udpStatus; int udpStatus;
GetUDPStatusRefreshUI(this.udpStatus); GetUDPStatusRefreshUI(this.udpStatus);
} }
/// UDP接收状态然后刷新监控界面 /// UDP接收状态然后刷新监控界面
class GetUDPStatusMonitorUI { class GetUDPStatusMonitorUI {
int udpStatus; int udpStatus;
GetUDPStatusMonitorUI(this.udpStatus); GetUDPStatusMonitorUI(this.udpStatus);
} }
/// ///
class GetFirstFrameGoPush { class GetFirstFrameGoPush {
bool isFirstFrame; bool isFirstFrame;
GetFirstFrameGoPush(this.isFirstFrame); GetFirstFrameGoPush(this.isFirstFrame);
} }
/// typeIndex /// typeIndex
class GetPasswordTypeUpdateIndex { class GetPasswordTypeUpdateIndex {
int passwordType; int passwordType;
GetPasswordTypeUpdateIndex(this.passwordType); GetPasswordTypeUpdateIndex(this.passwordType);
} }
@ -125,6 +138,7 @@ class AuthorizedAdminPageRefreshUI {
/// ///
class DoorLockLogListRefreshUI { class DoorLockLogListRefreshUI {
DateTime getDoorLockLogTime; DateTime getDoorLockLogTime;
DoorLockLogListRefreshUI(this.getDoorLockLogTime); DoorLockLogListRefreshUI(this.getDoorLockLogTime);
} }
@ -141,4 +155,4 @@ class AuthorizedAdministratorListPageRefreshUI {
/// ///
class MineInfoChangeRefreshUI { class MineInfoChangeRefreshUI {
MineInfoChangeRefreshUI(); MineInfoChangeRefreshUI();
} }