From b07ac6302b96aea8ea8954a8fce616dcf2d7d37c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Mon, 18 Mar 2024 16:16:51 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=88=87=E6=8D=A2=E8=93=9D=E7=89=99?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E3=80=822=E3=80=81=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=93=9D=E7=89=99=E6=A6=82=E7=8E=87=E8=BF=9E=E6=8E=A5=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=97=AE=E9=A2=98=E3=80=823=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=A6=82=E7=8E=87=E9=97=AA=E9=80=80=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=824=E3=80=81=E4=BF=AE=E5=A4=8D=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes star_lock/ios/Podfile.lock | 8 +- star_lock/lib/blue/blue_manage.dart | 646 ++++++++++++------ .../authorizedAdmin_logic.dart | 7 +- .../card/addCardType/addCardType_page.dart | 29 +- .../card/addICCard/addICCard_logic.dart | 13 +- .../card/cardDetail/cardDetail_logic.dart | 9 +- .../card/cardList/cardList_logic.dart | 17 +- .../doorLockLog/doorLockLog_logic.dart | 7 +- .../face/addFace/addFace_logic.dart | 9 +- .../face/faceDetail/faceDetail_logic.dart | 9 +- .../face/faceList/faceList_logic.dart | 17 +- .../addFingerprint/addFingerprint_logic.dart | 13 +- .../addFingerprintType_page.dart | 29 +- .../fingerprintDetail_logic.dart | 9 +- .../fingerprintList_logic.dart | 17 +- .../lockDetail/lockDetail_logic.dart | 27 +- .../lockDetail/lockDetail_page.dart | 15 +- .../lockOperatingRecord_logic.dart | 7 +- .../automaticBlocking_logic.dart | 35 +- .../adminOpenLockPassword_logic.dart | 15 +- .../basicInformation_logic.dart | 28 - .../uploadElectricQuantity_logic.dart | 9 +- .../burglarAlarm/burglarAlarm_logic.dart | 83 +-- .../configuringWifi_logic.dart | 9 +- .../wifiList/wifiList_logic.dart | 9 +- .../lockSet/lockSet/lockSet_logic.dart | 209 +++--- .../lockSet/lockSet/lockSet_page.dart | 4 +- .../lockSet/lockSet/lockSet_state.dart | 2 +- .../lockSoundSet/lockSoundSet_logic.dart | 35 +- .../lockSet/lockTime/lockTime_logic.dart | 25 +- .../lockSet/motorPower/motorPower_logic.dart | 12 +- .../normallyOpenMode_logic.dart | 34 +- .../openDoorDirection_logic.dart | 36 +- .../remoteUnlocking_logic.dart | 35 +- .../resetButton/resetButton_logic.dart | 35 +- .../passwordKey_perpetual_logic.dart | 13 +- .../passwordKey_perpetual_page.dart | 51 +- .../passwordKey_perpetual_state.dart | 1 + .../lockMian/lockMain/lockMain_logic.dart | 3 + .../gaode/lockAddressGaoDe_page.dart | 2 +- .../addLock/nearbyLock/nearbyLock_logic.dart | 64 +- .../addLock/nearbyLock/nearbyLock_page.dart | 16 +- .../addLock/nearbyLock/nearbyLock_state.dart | 5 +- .../mine/addLock/saveLock/saveLock_logic.dart | 21 +- .../mine/mineSet/mineSet/mineSet_logic.dart | 2 +- .../starLockApplication.dart | 1 + star_lock/pubspec.yaml | 3 +- 48 files changed, 878 insertions(+), 807 deletions(-) diff --git a/.DS_Store b/.DS_Store index c3deee4d65995d7a811ee7e009b64bf0a6d3cf17..a95f5409ebc2504e185257b3930bfe0a53414672 100644 GIT binary patch delta 474 zcmZoMXfc=|#>B!ku~2NHo}wTh0|Nsi1A_oVPP$=ma(-^XWI_60CW~x&-oy3xXUqXx4m1Fv0%1LN703=?VAue104Kv_L8dqL z$ac%8o$&(86f=}CBr+5+#53eDB)qF;Q%yo}wrd0|Nsi1A_nqLp(zcLq0C}}lMO^zCO={o uo-D= 1.8.0) + - app_settings (5.1.1): + - Flutter - audio_service (0.0.1): - Flutter - audio_session (0.0.1): @@ -109,6 +111,7 @@ DEPENDENCIES: - aliyun_push (from `.symlinks/plugins/aliyun_push/ios`) - amap_flutter_location (from `.symlinks/plugins/amap_flutter_location/ios`) - amap_flutter_map (from `.symlinks/plugins/amap_flutter_map/ios`) + - app_settings (from `.symlinks/plugins/app_settings/ios`) - audio_service (from `.symlinks/plugins/audio_service/ios`) - audio_session (from `.symlinks/plugins/audio_session/ios`) - audioplayers_darwin (from `.symlinks/plugins/audioplayers_darwin/ios`) @@ -166,6 +169,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/amap_flutter_location/ios" amap_flutter_map: :path: ".symlinks/plugins/amap_flutter_map/ios" + app_settings: + :path: ".symlinks/plugins/app_settings/ios" audio_service: :path: ".symlinks/plugins/audio_service/ios" audio_session: @@ -236,6 +241,7 @@ SPEC CHECKSUMS: amap_flutter_map: 979e54d227cedac6c7504a2151bfbf3bcf96760a AMapFoundation: 9885c48fc3a78fdfb84a0299a2293e56ea3c9fec AMapLocation: 5248aec2455ebb5d104b367813c946430a2ee033 + app_settings: 017320c6a680cdc94c799949d95b84cb69389ebc audio_service: f509d65da41b9521a61f1c404dd58651f265a567 audio_session: 4f3e461722055d21515cf3261b64c973c062f345 audioplayers_darwin: 877d9a4d06331c5c374595e46e16453ac7eafa40 @@ -272,6 +278,6 @@ SPEC CHECKSUMS: video_player_avfoundation: 81e49bb3d9fb63dccf9fa0f6d877dc3ddbeac126 webview_flutter_wkwebview: 4f3e50f7273d31e5500066ed267e3ae4309c5ae4 -PODFILE CHECKSUM: 2d54cef87a0ac87750282877d7a79b735ed5c517 +PODFILE CHECKSUM: 8406bb0e8f1c4b5dff3955810b207d90193914a0 COCOAPODS: 1.14.3 diff --git a/star_lock/lib/blue/blue_manage.dart b/star_lock/lib/blue/blue_manage.dart index 951b80d6..55574400 100644 --- a/star_lock/lib/blue/blue_manage.dart +++ b/star_lock/lib/blue/blue_manage.dart @@ -1,52 +1,67 @@ import 'dart:async'; +import 'dart:io'; import 'package:flutter_easyloading/flutter_easyloading.dart'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:get/get.dart'; import 'io_tool/io_model.dart'; import 'io_tool/io_tool.dart'; import 'io_tool/manager_event_bus.dart'; import 'reciver_data.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; //连接状态回调 -typedef ConnectStateCallBack = Function(DeviceConnectionState connectionState); +typedef ConnectStateCallBack = Function(BluetoothConnectionState connectionState); +typedef ScanDevicesCallBack = Function(List); class BlueManage { - FlutterReactiveBle? _flutterReactiveBle; - final List scanDevices = []; + final List scanDevices = []; // 用来写入的服务id - final Uuid _serviceIdConnect = Uuid.parse("fff0"); + final Guid _serviceIdConnect = Guid("fff0"); // 用来写入的服务id - final Uuid _serviceIdWrite = Uuid.parse('0000FFF0-0000-1000-8000-00805F9B34FB'); + final Guid _serviceIdWrite = Guid('0000FFF0-0000-1000-8000-00805F9B34FB'); // 用来订阅的特征id - final Uuid _characteristicIdSubscription = Uuid.parse("fff1"); + final Guid _characteristicIdSubscription = Guid("fff1"); // 用来写入的特征id - final Uuid _characteristicIdWrite = Uuid.parse("fff2"); + final Guid _characteristicIdWrite = Guid("fff2"); // 监听发送事件 StreamSubscription? _sendStreamSubscription; // 监听蓝牙扫描的事件 - StreamSubscription? _scanSubscription; + // StreamSubscription? _scanSubscription; // 监听蓝牙连接的事件 - StreamSubscription? _currentConnectionStream; + // StreamSubscription? _currentConnectionStream; + + // StreamSubscription>? _scanResultsSubscription; + StreamSubscription? _connectionStateSubscription; + + StreamSubscription? _mtuSubscription; + int? _mtuSize = 20; // 当前连接设备的名字 String connectDeviceName = ""; // 当前连接设备的mac地址 String connectDeviceMacAddress = ""; + // 当前连接的设备 + BluetoothDevice? bluetoothConnectDevice; + // 当前扫描到结果要连接设备 + ScanResult? scanResult; // 监听蓝牙连接状态 - DeviceConnectionState? deviceConnectionState = DeviceConnectionState.disconnected; + BluetoothConnectionState? bluetoothConnectionState = BluetoothConnectionState.disconnected; + + BluetoothAdapterState? _adapterState = BluetoothAdapterState.unknown; + StreamSubscription? _adapterStateStateSubscription; static BlueManage? _manager; BlueManage._init(){ - // _initBlue(); + _initBlue(); } static BlueManage? shareManager() { _manager ??= BlueManage._init(); - _manager!._initBlue(); + // _manager!._initBlue(); return _manager; } @@ -54,21 +69,94 @@ class BlueManage { BlueManage? get manager => shareManager(); void _initBlue(){ - // print("蓝牙功能初始化了"); - _flutterReactiveBle ??= FlutterReactiveBle(); + print("蓝牙功能初始化监听"); _initSendStreamSubscription(); + _initAdapterStateStateSubscription(); + // _initListenscanResults(); + // _initListenConnectionState(); + } + + void _initGetMtuSubscription() { + _mtuSubscription ??= bluetoothConnectDevice!.mtu.listen((value) { + _mtuSize = value - 3; + print('mtuSize:$_mtuSize'); + }); + } + + void _initAdapterStateStateSubscription() { + _adapterStateStateSubscription ??= FlutterBluePlus.adapterState.listen((state) { + _adapterState = state; + }); + } + + // void _initListenscanResults() { + // var subscription = FlutterBluePlus.scanResults.listen((results) { + // scanDevices.clear(); + // for (var scanResult in results) { + // // 判断名字为空的直接剔除 + // // if (scanResult.device.advName.isEmpty) { + // // return; + // // } + // print("scanResult.device.advName:${scanResult.device.advName}" + // " scanResult.advertisementData.serviceUuids:${scanResult.advertisementData.serviceUuids}" + // " rssi:${scanResult.rssi}"); + // if (((scanResult.advertisementData.serviceUuids.isNotEmpty ? scanResult.advertisementData.serviceUuids[0] : "").toString().contains("758824")) && (scanResult.rssi >= -100)) { + // // 查询id相同的元素 + // final knownDeviceIndex = scanDevices.indexWhere((d) => d.advertisementData.advName == scanResult.advertisementData.advName); + // // 不存在的时候返回-1 + // if (knownDeviceIndex >= 0) { + // scanDevices[knownDeviceIndex] = scanResult; + // } else { + // scanDevices.add(scanResult); + // } + // } + // } + // EventBusManager().eventBusFir(scanDevices); + // // FlutterBluePlus.stopScan(); + // }, onError: (e) { + // print("Scan Error:$e", ); + // }); + // + // FlutterBluePlus.cancelWhenScanComplete(subscription); + + // FlutterBluePlus.isScanning.listen((state) { + // if (state) { + // print('Scanning'); + // } else { + // print('Not scanning'); + // } + // }); + // } + + void _initListenConnectionState() { + _connectionStateSubscription?.cancel(); + _connectionStateSubscription = null; + + _connectionStateSubscription = bluetoothConnectDevice!.connectionState.listen((state) async { + bluetoothConnectionState = state; + Get.log("蓝牙连接状态:$state"); + }); } void _initSendStreamSubscription() { _sendStreamSubscription ??= EventBusManager().eventBus!.on().listen((EventSendModel model) { if (model.sendChannel == DataChannel.ble) { - // managerAppWriteData(model.data); - _flutterReactiveBle!.statusStream.listen((status) { - if (status == BleStatus.ready) { - // 蓝牙已开启,可以进行蓝牙操作 - writeCharacteristicWithResponse(model.data); - }else{ - Get.log("写入数据 蓝牙未开启,不能进行蓝牙操作"); + FlutterBluePlus.isSupported.then((isAvailable) async { + if (isAvailable) { + if (_adapterState == BluetoothAdapterState.on) { + // 蓝牙已开启,可以进行蓝牙操作 + writeCharacteristicWithResponse(model.data); + } else { + try { + if (Platform.isAndroid) { + await FlutterBluePlus.turnOn(); + } + } catch (e) { + Get.log("Error Turning On:"); + } + } + } else { + Get.log("写入数据 蓝牙不可用,不能进行蓝牙操作"); } }); } @@ -76,164 +164,196 @@ class BlueManage { } /// 开始扫描蓝牙设备 - void startScan({List? idList}) { - // List? list = _flutterReactiveBle!.getDiscoveredServices("deviceId").then((value)); - _flutterReactiveBle!.statusStream.listen((status) { - if (status == BleStatus.ready) { - // 蓝牙已开启,可以进行蓝牙操作 - scanDevices.clear(); - _scanSubscription = _flutterReactiveBle!.scanForDevices(withServices:[]).listen((device) { - // 判断名字为空的直接剔除 - if (device.name.isEmpty) { - return; - } - print("startScanDevice:$device"); - if (((device.serviceUuids.isNotEmpty ? device.serviceUuids[0] : "").toString().contains("758824")) && (device.rssi >= -100)) { - // 查询id相同的元素 - final knownDeviceIndex = scanDevices.indexWhere((d) => d.id == device.id); - // 不存在的时候返回-1 - if (knownDeviceIndex >= 0) { - scanDevices[knownDeviceIndex] = device; - } else { - scanDevices.add(device); + Future startScan(int timeout, ScanDevicesCallBack scanDevicesCallBack, {List? idList}) async { + FlutterBluePlus.isSupported.then((isAvailable) async { + if (isAvailable) { + if (_adapterState == BluetoothAdapterState.on) { + try { + FlutterBluePlus.startScan(timeout: Duration(seconds: timeout)); + + var subscription = FlutterBluePlus.scanResults.listen((results) { + scanDevices.clear(); + for (var scanResult in results) { + // 判断名字为空的直接剔除 + // if (scanResult.device.advName.isEmpty) { + // return; + // } + Get.log("scanResult.device.advName:${scanResult.device.advName}" + " scanResult.advertisementData.serviceUuids:${scanResult.advertisementData.serviceUuids}" + " rssi:${scanResult.rssi}"); + if (((scanResult.advertisementData.serviceUuids.isNotEmpty ? scanResult.advertisementData.serviceUuids[0] : "").toString().contains("758824")) && (scanResult.rssi >= -100)) { + // 查询id相同的元素 + final knownDeviceIndex = scanDevices.indexWhere((d) => d.advertisementData.advName == scanResult.advertisementData.advName); + // 不存在的时候返回-1 + if (knownDeviceIndex >= 0) { + scanDevices[knownDeviceIndex] = scanResult; + } else { + scanDevices.add(scanResult); + } + } + } + scanDevicesCallBack(scanDevices); + // EventBusManager().eventBusFir(scanDevices); + // FlutterBluePlus.stopScan(); + }, onError: (e) { + print("Scan Error:$e", ); + }); + + FlutterBluePlus.cancelWhenScanComplete(subscription); + } catch (e) { + Get.log("扫描失败"); } - EventBusManager().eventBusFir(scanDevices); - } - }, onError: (Object e) { - print('Device scan fails with error: $e'); - }); - }else{ - Get.log("开始扫描 蓝牙未开启,不能进行蓝牙操作"); + } else { + try { + if (Platform.isAndroid) { + await FlutterBluePlus.turnOn(); + } + } catch (e) { + Get.log("Error Turning On:"); + } + }; + } else { + Get.log("开始扫描 蓝牙不可用,不能进行蓝牙操作"); } }); } /// 调用发送数据 Future bludSendData(String deviceName, ConnectStateCallBack stateCallBack, {bool isAddEquipment = false}) async { - _flutterReactiveBle!.statusStream.listen((status) { - Get.log("_flutterReactiveBle.status:$status"); - if(deviceName.isEmpty) { - Get.log("deviceName为空"); - return; - } - if (status == BleStatus.ready) { - // 蓝牙已开启,可以进行蓝牙操作 - if(deviceConnectionState != DeviceConnectionState.connected){ - if(isAddEquipment == false){ - // print("666666666"); - startScan(); + FlutterBluePlus.isSupported.then((isAvailable) async { + if (isAvailable) { + if (_adapterState == BluetoothAdapterState.on) { + // 蓝牙已开启,可以进行蓝牙操作 + if(bluetoothConnectionState != BluetoothConnectionState.connected){ + _connect(deviceName, (state){ + // if(bluetoothConnectionState != BluetoothConnectionState.connected){ + // stateCallBack(bluetoothConnectionState!); + // }else{ + // stateCallBack(bluetoothConnectionState!); + // } + stateCallBack(bluetoothConnectionState!); + }, isAddEquipment: isAddEquipment); + }else{ + stateCallBack(bluetoothConnectionState!); } - - _connect(deviceName, (state){ - stateCallBack(deviceConnectionState!); - }); - }else{ - // stopScan(); - stateCallBack(deviceConnectionState!); - } - }else{ - Get.log("调用发送数据 蓝牙未开启,不能进行蓝牙操作"); + } else { + try { + if (Platform.isAndroid) { + await FlutterBluePlus.turnOn(); + } + } catch (e) { + Get.log("Error Turning On:"); + } + }; + } else { + Get.log("开始扫描 蓝牙不可用,不能进行蓝牙操作"); } }); } - /// 连接监听状态 - Future _connect(String deviceName, ConnectStateCallBack connectStateCallBack) async { + /// 连接 + Future _connect(String deviceName, ConnectStateCallBack connectStateCallBack, {bool isAddEquipment = false}) async { connectDeviceName = deviceName; + List devicesList = scanDevices; + if(isAddEquipment == false){ + startScan(10, (List scanDevices){ + print("扫描到的设备:$scanDevices"); + devicesList = scanDevices; + _connectDevice(devicesList, deviceName, connectStateCallBack, isAddEquipment: isAddEquipment); + }); + }else{ + _connectDevice(devicesList, deviceName, connectStateCallBack, isAddEquipment: isAddEquipment); + } + } + + Future _connectDevice( List devicesList, String deviceName, ConnectStateCallBack connectStateCallBack, {bool isAddEquipment = false}) async { // 判断数组列表里面是否有这个设备 - final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName); + print("devicesList:$devicesList"); + final knownDeviceIndex = devicesList.indexWhere((d) => d.advertisementData.advName == deviceName); if (knownDeviceIndex >= 0) { // 存在的时候赋值 - connectDeviceMacAddress = scanDevices[knownDeviceIndex].id; - } else { - // 不存在的时候返回-1 然后循环5秒 - var index = 0; - Completer? completer = Completer(); - Timer.periodic(const Duration(seconds: 1), (timer) async { - ///定时任务 - // print("timer index0:$index"); - if(index >= 9){ - // 当超过5秒的时候取消定时任务 弹窗显示连接失败 - connectDeviceMacAddress = ""; - connectStateCallBack(DeviceConnectionState.disconnected); - completer.complete(); - stopScan(); - timer.cancel(); - // deviceConnectionState = DeviceConnectionState.disconnected; - // print("timer index1:$index"); - }else{ - // 每秒判断数组列表里面是否有这个设备 - final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName); + connectDeviceMacAddress = devicesList[knownDeviceIndex].advertisementData.advName; - if (knownDeviceIndex >= 0) { - // 存在的时候销毁定时器,赋值 - connectDeviceMacAddress = scanDevices[knownDeviceIndex].id; - stopScan(); - completer.complete(); - timer.cancel(); - // print("timer index2:$index"); + bluetoothConnectDevice = devicesList[knownDeviceIndex].device; + print('bluetoothConnectDevice: $bluetoothConnectDevice'); + scanResult = devicesList[knownDeviceIndex]; - // var uuidStr = (scanDevices[knownDeviceIndex].serviceUuids.isNotEmpty ? scanDevices[knownDeviceIndex].serviceUuids[0] : "").toString(); - // if(uuidStr[31] == "0"){ - // // 未配对 表示这把锁已被强制初始化 处于可添加状态 不再连接 - // EasyLoading.showToast("当前设备已被清除配对,请删除后重新添加", duration: 2000.milliseconds); - // Future.delayed(2100.milliseconds); - // connectStateCallBack(DeviceConnectionState.disconnected); - // return; - // } - } else { - // 不存在的时候返回-1 然后循环5秒 - index++; - print("index:$index"); - } - } - }); - // 等待Completer完成 - await completer.future; + _initGetMtuSubscription(); + _initListenConnectionState(); } print("1 connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName"); // stopScan(); if (connectDeviceMacAddress.isEmpty) { + // connectStateCallBack(BluetoothConnectionState.disconnected!); return; } - /// 用来判断是否返回了连接结果 还是放了一段时间后蓝牙主动断开的 - var isReturnedConnectResults = false; - _currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(seconds: 5)).listen((connectionStateUpdate) async { - // 获取状态 - deviceConnectionState = connectionStateUpdate.connectionState; - stopScan(); - print('2 deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}'); - if (connectionStateUpdate.connectionState == DeviceConnectionState.connected) { - isReturnedConnectResults = true; - // 如果状态是连接的开始发现服务 - try { - _subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: _characteristicIdSubscription, serviceId: _serviceIdConnect, deviceId: connectDeviceMacAddress)); - print('Discovering services finished'); + Get.log("调用了停止扫描的方法"); + await stopScan(); - deviceConnectionState = connectionStateUpdate.connectionState; - connectStateCallBack(deviceConnectionState!); - } on Exception catch (e) { - deviceConnectionState = DeviceConnectionState.disconnected; - connectStateCallBack(deviceConnectionState!); - print('Error occurred when discovering services: $e'); - rethrow; - } - } else if (connectionStateUpdate.connectionState == DeviceConnectionState.disconnected) { - // 如果状态是断开的 - deviceConnectionState = connectionStateUpdate.connectionState; - if(isReturnedConnectResults == false){ - isReturnedConnectResults = true; - // 如果是在连接中断开的 - connectStateCallBack(deviceConnectionState!); + if ((scanResult!.advertisementData.serviceUuids[0].toString()[31] == "0") && isAddEquipment == false) { + connectStateCallBack(BluetoothConnectionState.disconnected!); + EasyLoading.showToast("该锁已被重置", duration: 2000.milliseconds); + return; + } + + // 重连三次 + int maxAttempts = 3; + int attempt = 0; + while (attempt < maxAttempts) { + try { + await bluetoothConnectDevice!.connect(timeout: 5.seconds); + break; // If the connection is successful, break the loop + } catch (e) { + Get.log('Failed to connect: $e'); + attempt++; // Increase the attempt count + if (attempt < maxAttempts) { + Get.log('Retrying connection...'); } } - print('ConnectionState for device $connectDeviceMacAddress : ${connectionStateUpdate.connectionState}'); - }, onError: (Object e) { - deviceConnectionState = DeviceConnectionState.disconnected; - connectStateCallBack(deviceConnectionState!); - print('Connecting to device $connectDeviceMacAddress resulted in error $e'); - }); + } + + if (attempt >= maxAttempts) { + Get.log('Failed to connect after $maxAttempts attempts.'); + connectStateCallBack(BluetoothConnectionState.disconnected!); + } + + // await bluetoothConnectDevice!.connect(); + print("5555555:回调状态:$bluetoothConnectionState"); + if (bluetoothConnectionState == BluetoothConnectionState.connected) { + try { + bluetoothConnectDevice!.discoverServices().then((services) { + print("333333333"); + for (BluetoothService service in services) { + // print("11111service.remoteId:${service.remoteId}" + // " service.uuid:${service.uuid}" + // " service.characteristics:${service.characteristics}" + // " service.includedServices:${service.includedServices}"); + if(service.uuid == _serviceIdConnect){ + for (BluetoothCharacteristic characteristic in service.characteristics) { + // print("22222characteristic.remoteId:${characteristic.remoteId}" + // " characteristic.uuid:${characteristic.uuid}" + // " characteristic.secondaryServiceUuid:${characteristic.secondaryServiceUuid}" + // " characteristic.characteristicUuid:${characteristic.characteristicUuid}"); + if (characteristic.characteristicUuid == _characteristicIdSubscription) { + print("44444444"); + _subScribeToCharacteristic(characteristic); + print('Discovering services finished'); + bluetoothConnectionState = BluetoothConnectionState.connected; + connectStateCallBack(bluetoothConnectionState!); + } + } + } + } + }); + } on Exception catch (e) { + bluetoothConnectionState = BluetoothConnectionState.disconnected; + Get.log("5555 回调状态:$bluetoothConnectionState"); + connectStateCallBack(bluetoothConnectionState!); + print('Error occurred when discovering services: $e'); + rethrow; + } + } } // 听上报来的数据,参数来自前面扫描到的结果 @@ -241,9 +361,11 @@ class BlueManage { // 保存上一次的数据,用来判断是否收到重复的数据 var lastTimeData = []; int? dataLen; - _subScribeToCharacteristic(QualifiedCharacteristic characteristic) { - _flutterReactiveBle!.subscribeToCharacteristic(characteristic).listen((data) { - if(data == lastTimeData){ + _subScribeToCharacteristic(BluetoothCharacteristic characteristic) async { + final subscription = characteristic.onValueReceived.listen((data) { + print("启动对特性的通知。当特性的值发生变化时,设备会发送一个通知"); + print("订阅获取的数据:$data"); + if(data == lastTimeData || data.isEmpty){ return; }else{ lastTimeData = data; @@ -279,97 +401,179 @@ class BlueManage { allData = []; } } - }, onError: (dynamic error) { - EasyLoading.dismiss(); - print("subscribeToCharacteristic error:$error"); }); + +// cleanup: cancel subscription when disconnected + bluetoothConnectDevice!.cancelWhenDisconnected(subscription); + +// enable notifications + await characteristic.setNotifyValue(true); + + // characteristic.setNotifyValue(true).then((_) { + // print("启动对特性的通知。当特性的值发生变化时,设备会发送一个通知"); + // characteristic.lastValueStream.listen((data) { + // print("订阅获取的数据:$data"); + // // do something with new value + // if(data == lastTimeData || data.isEmpty){ + // return; + // }else{ + // lastTimeData = data; + // } + // // code to handle incoming data + // // print("subscribeToCharacteristic: deviceId = ${characteristic.deviceId} characteristicId =${characteristic.characteristicId}---上报来的数据data = $data"); + // if ((data[0] == 0xEF) && (data[1] == 0x01) && (data[2] == 0xEE) && (data[3] == 0x02)) { + // // 当包有头时 + // // 判断是否需要分包 + // dataLen = data[8] * 256 + data[9]; // 高16位用来指示后面数据块内容的长度 + // // print("dataLen1111:$dataLen getDataLength:${data.length}"); + // if (dataLen! + 12 > data.length) { + // // 当前包的长度小于实际的包时 分包添加 不解析 + // allData.addAll(data); + // } else { + // // 当前包的长度小于实际的包时 不分包 解析 + // allData.addAll(data); + // // print("dataLen2222:$dataLen getDataLength:${data.length}"); + // CommandReciverManager.appDataReceive(allData); + // // 发送完解析初始化数组 + // allData = []; + // } + // } else { + // // 当包没有头时 是分包的包 直接添加 + // allData.addAll(data); + // // var len = allData[8] * 256 + allData[9]; + // // print("dataLen3333:$dataLen"); + // if ((dataLen! + 14) <= allData.length) { + // // print("44444数据被解析了"); + // // 当长度小于等于当前包的数据时 直接解析数据 + // CommandReciverManager.appDataReceive(allData); + // // 发送完解析初始化数组 + // allData = []; + // } + // } + // }); + // }); } // 写入 Future writeCharacteristicWithResponse(List value) async { - QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: _characteristicIdWrite, serviceId: _serviceIdWrite, deviceId: connectDeviceMacAddress); - int mtuLength = await _flutterReactiveBle!.requestMtu(deviceId: characteristic.deviceId, mtu: 512); - print("mtuLength:$mtuLength"); - try { - List valueList = value; - List subData = splitList(valueList, mtuLength); - print('得到的分割数据:$subData'); + bluetoothConnectDevice!.discoverServices().then((services) async { + for (BluetoothService service in services) { + // print("33333 service.remoteId:${service.remoteId}" + // " service.uuid:${service.uuid}\n\n" + // " service.characteristics:${service.characteristics}\n\n" + // " service.includedServices:${service.includedServices}"); + if (service.uuid == _serviceIdConnect) { + for (BluetoothCharacteristic characteristic in service + .characteristics) { + // print("44444 characteristic.remoteId:${characteristic.remoteId}" + // " characteristic.uuid:${characteristic.uuid}\n\n" + // " characteristic.secondaryServiceUuid:${characteristic + // .secondaryServiceUuid}\n\n" + // " characteristic.characteristicUuid:${characteristic + // .characteristicUuid}"); + if (characteristic.characteristicUuid == _characteristicIdWrite) { + try { + List valueList = value; + List subData = splitList(valueList, _mtuSize!); + print( + 'writeCharacteristicWithResponse 得到的分割数据:$subData'); - for (int i = 0; i < subData.length; i++) { - await _flutterReactiveBle! - .writeCharacteristicWithResponse(characteristic, value: subData[i]) - .then((value) async { - await Future.delayed(const Duration(milliseconds: 1)) - .then((value) async { - print('分包发送成功了'); - }); - }); + for (int i = 0; i < subData.length; i++) { + await characteristic.write(subData[i]).then((value) async { + await Future.delayed(const Duration(milliseconds: 1)).then(( + value) async { + print('分包发送成功了'); + }); + }); + } + } on Exception catch (e, s) { + print('Error occurred when writing: $e'); + print(s); + rethrow; + } + } + } + } } - } on Exception catch (e, s) { - print('Error occurred when writing: $e'); - // ignore: avoid_print - print(s); - rethrow; - } + }); + // List services = await bluetoothConnectDevice!.discoverServices(); + // BluetoothCharacteristic characteristic = services + // .firstWhere((service) => service.uuid == _serviceIdWrite) + // .characteristics + // .firstWhere((char) => char.uuid == _characteristicIdWrite); + // try { + // List valueList = value; + // List subData = splitList(valueList, _mtuSize!); + // print('writeCharacteristicWithResponse 得到的分割数据:$subData'); + // + // for (int i = 0; i < subData.length; i++) { + // await characteristic.write(subData[i]).then((value) async { + // await Future.delayed(const Duration(milliseconds: 1)).then((value) async { + // print('分包发送成功了'); + // }); + // }); + // } + // } on Exception catch (e, s) { + // print('Error occurred when writing: $e'); + // print(s); + // rethrow; + // } } // 读取 - Future> _readCharacteristic(QualifiedCharacteristic characteristic) async { - try { - final result = - await _flutterReactiveBle!.readCharacteristic(characteristic); - print("readListresult$result"); - return result; - } on Exception catch (e, s) { - print( - 'Error occurred when reading ${characteristic.characteristicId} : $e', - ); - rethrow; - } - } + // Future> _readCharacteristic(QualifiedCharacteristic characteristic) async { + // try { + // final result = + // await _flutterReactiveBle!.readCharacteristic(characteristic); + // print("readListresult$result"); + // return result; + // } on Exception catch (e, s) { + // print( + // 'Error occurred when reading ${characteristic.characteristicId} : $e', + // ); + // rethrow; + // } + // } - Future writeCharacteristicWithoutResponse( - QualifiedCharacteristic characteristic, List value) async { - try { - await _flutterReactiveBle! - .writeCharacteristicWithoutResponse(characteristic, value: value); - } on Exception catch (e, s) { - // ignore: avoid_print - print(s); - rethrow; - } - } + // Future writeCharacteristicWithoutResponse( + // QualifiedCharacteristic characteristic, List value) async { + // try { + // await _flutterReactiveBle! + // .writeCharacteristicWithoutResponse(characteristic, value: value); + // } on Exception catch (e, s) { + // // ignore: avoid_print + // print(s); + // rethrow; + // } + // } // 停止扫描蓝牙设备 - void stopScan() { - // print("444444444"); - if(_scanSubscription != null){ - // print("555555555555"); - _scanSubscription?.cancel(); - _scanSubscription = null; + Future stopScan() async { + try { + await FlutterBluePlus.stopScan(); + } catch (e) { + Get.log("停止扫描失败"); } } // 断开连接 - Future disconnect(String deviceMAC) async { + Future disconnect() async { try { - connectDeviceMacAddress = ""; - // if(_currentConnectionStream != null){ - _currentConnectionStream?.cancel(); - _currentConnectionStream = null; - // } - - print('disconnecting to device: $connectDeviceName'); + connectDeviceMacAddress = ""; + await bluetoothConnectDevice!.disconnect(); + Get.log("断开连接成功"); } on Exception catch (e, _) { print("Error disconnecting from a device: $e"); } finally { - deviceConnectionState = DeviceConnectionState.disconnected; + bluetoothConnectionState = BluetoothConnectionState.disconnected; } } disposed() { _sendStreamSubscription?.cancel(); - _currentConnectionStream?.cancel(); - _scanSubscription?.cancel(); + _mtuSubscription!.cancel(); + // _scanResultsSubscription!.cancel(); + _adapterStateStateSubscription!.cancel(); + _connectionStateSubscription!.cancel(); } } diff --git a/star_lock/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart b/star_lock/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart index 0bc4a172..612508d3 100644 --- a/star_lock/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart +++ b/star_lock/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/blue/io_type.dart'; @@ -162,8 +163,8 @@ class AuthorizedAdminLogic extends BaseGetXController { // 转移权限 Future transferPermissionsAction() async { BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); diff --git a/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart b/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart index 18791985..9b521b34 100644 --- a/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart +++ b/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart @@ -119,7 +119,6 @@ class _AddCardPageState extends State { String titleStr, String rightTitle, TextEditingController controller) { return Column( children: [ - Container(height: 10.h), CommonItem( leftTitel: titleStr, rightTitle: "", @@ -142,16 +141,12 @@ class _AddCardPageState extends State { action: () async { Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { - setState(() { - setState(() { state.beginTime.value = - '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; + '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; state.beginTimeTimestamp.value = DateTime.parse(state.beginTime.value) .millisecondsSinceEpoch .toString(); - }); - }); }); })), Obx(() => CommonItem( @@ -161,16 +156,12 @@ class _AddCardPageState extends State { action: () { Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { - setState(() { - setState(() { state.endTime.value = - '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; + '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; state.endTimeTimestamp.value = DateTime.parse(state.endTime.value) .millisecondsSinceEpoch .toString(); - }); - }); }); })), Container(height: 10.h), @@ -181,21 +172,21 @@ class _AddCardPageState extends State { Widget keyBottomWidget() { return Column( children: [ - CommonItem( + Obx(() => CommonItem( leftTitel: "是否是管理员", rightTitle: "", isTipsImg: false, isHaveRightWidget: true, rightWidget: SizedBox( - width: 60.w, height: 50.h, child: _isAdmin())), + width: 60.w, height: 50.h, child: _isAdmin()))), SizedBox(height: 10.h), - CommonItem( + Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.stressCard!.tr, rightTitle: "", isTipsImg: false, isHaveRightWidget: true, rightWidget: SizedBox( - width: 60.w, height: 50.h, child: _isStressFingerprint())), + width: 60.w, height: 50.h, child: _isStressFingerprint()))), SizedBox(height: 30.h), SubmitBtn( btnName: TranslationLoader.lanKeys!.next!.tr, @@ -359,9 +350,7 @@ class _AddCardPageState extends State { thumbColor: CupertinoColors.white, value: state.isStressFingerprint.value, onChanged: (value) { - setState(() { - state.isStressFingerprint.value = value; - }); + state.isStressFingerprint.value = value; }, ); } @@ -374,9 +363,7 @@ class _AddCardPageState extends State { thumbColor: CupertinoColors.white, value: state.isAdministrator.value, onChanged: (value) { - setState(() { - state.isAdministrator.value = value; - }); + state.isAdministrator.value = value; }, ); } diff --git a/star_lock/lib/main/lockDetail/card/addICCard/addICCard_logic.dart b/star_lock/lib/main/lockDetail/card/addICCard/addICCard_logic.dart index 442addc2..fa53025d 100644 --- a/star_lock/lib/main/lockDetail/card/addICCard/addICCard_logic.dart +++ b/star_lock/lib/main/lockDetail/card/addICCard/addICCard_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -221,8 +222,8 @@ class AddICCardLogic extends BaseGetXController{ print("没有任何响应"); Get.close(1); }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ cancelBlueConnetctToastTimer(); var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -248,7 +249,7 @@ class AddICCardLogic extends BaseGetXController{ privateKey:getPrivateKeyList, token: getTokenList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected){ + } else if (deviceConnectionState == BluetoothConnectionState.disconnected){ if(state.ifCurrentScreen.value == true){ showBlueConnetctToast(); } @@ -260,8 +261,8 @@ class AddICCardLogic extends BaseGetXController{ // 添加胁迫卡片 Future senderAddStressICCard() async { - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); diff --git a/star_lock/lib/main/lockDetail/card/cardDetail/cardDetail_logic.dart b/star_lock/lib/main/lockDetail/card/cardDetail/cardDetail_logic.dart index 8e71e68d..1c3462fa 100644 --- a/star_lock/lib/main/lockDetail/card/cardDetail/cardDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/card/cardDetail/cardDetail_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -99,8 +100,8 @@ class CardDetailLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -124,7 +125,7 @@ class CardDetailLogic extends BaseGetXController{ privateKey:getPrivateKeyList, token: getTokenList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/card/cardList/cardList_logic.dart b/star_lock/lib/main/lockDetail/card/cardList/cardList_logic.dart index a5073dc0..f665f1e8 100644 --- a/star_lock/lib/main/lockDetail/card/cardList/cardList_logic.dart +++ b/star_lock/lib/main/lockDetail/card/cardList/cardList_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../blue/blue_manage.dart'; @@ -206,8 +207,8 @@ class CardListLogic extends BaseGetXController { // 查询卡片状态 Future senderCheckingCardStatus() async { - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -234,8 +235,8 @@ class CardListLogic extends BaseGetXController { // 查询用户、指纹、密码、卡片数量(用于判断是否同步) Future senderCheckingUserInfoCount() async { - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -265,8 +266,8 @@ class CardListLogic extends BaseGetXController { showBlueConnetctToastTimer(action: (){ dismissEasyLoading(); }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -289,7 +290,7 @@ class CardListLogic extends BaseGetXController { privateKey:getPrivateKeyList, token: getTokenList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); if(state.ifCurrentScreen.value == true){ diff --git a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart index 6230e790..a05295ca 100644 --- a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart +++ b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart @@ -2,8 +2,9 @@ import 'dart:async'; import 'dart:convert'; import 'package:flutter/services.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_entity.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_state.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyDetail/keyOperationRecord/keyOperationRecord_entity.dart'; @@ -160,8 +161,8 @@ class DoorLockLogLogic extends BaseGetXController { // 查询事件记录(时间查询) Future senderReferEventRecordTime(int time) async { BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); diff --git a/star_lock/lib/main/lockDetail/face/addFace/addFace_logic.dart b/star_lock/lib/main/lockDetail/face/addFace/addFace_logic.dart index 92ecfc40..f8211f03 100644 --- a/star_lock/lib/main/lockDetail/face/addFace/addFace_logic.dart +++ b/star_lock/lib/main/lockDetail/face/addFace/addFace_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_protocol/io_addFace.dart'; import 'package:star_lock/blue/io_type.dart'; @@ -190,8 +191,8 @@ class AddFaceLogic extends BaseGetXController { Get.close(1); }); BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { cancelBlueConnetctToastTimer(); var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -220,7 +221,7 @@ class AddFaceLogic extends BaseGetXController { privateKey: getPrivateKeyList, token: getTokenList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); } diff --git a/star_lock/lib/main/lockDetail/face/faceDetail/faceDetail_logic.dart b/star_lock/lib/main/lockDetail/face/faceDetail/faceDetail_logic.dart index db54f08a..71b796d5 100644 --- a/star_lock/lib/main/lockDetail/face/faceDetail/faceDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/face/faceDetail/faceDetail_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_protocol/io_addFace.dart'; import 'package:star_lock/blue/io_type.dart'; @@ -100,8 +101,8 @@ class FaceDetailLogic extends BaseGetXController { state.sureBtnState.value = 0; }); BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -125,7 +126,7 @@ class FaceDetailLogic extends BaseGetXController { privateKey: getPrivateKeyList, token: getTokenList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/face/faceList/faceList_logic.dart b/star_lock/lib/main/lockDetail/face/faceList/faceList_logic.dart index 94be07d2..c99cf332 100644 --- a/star_lock/lib/main/lockDetail/face/faceList/faceList_logic.dart +++ b/star_lock/lib/main/lockDetail/face/faceList/faceList_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/blue/io_protocol/io_addFace.dart'; import 'package:star_lock/blue/io_protocol/io_queryingFaceStatus.dart'; import 'package:star_lock/blue/io_type.dart'; @@ -244,8 +245,8 @@ class FaceListLogic extends BaseGetXController { // 获取人脸状态 Future senderQueryingFaceStatus() async { BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -273,8 +274,8 @@ class FaceListLogic extends BaseGetXController { // 查询用户、指纹、密码、卡片数量(用于判断是否同步) Future senderCheckingUserInfoCount() async { BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -305,8 +306,8 @@ class FaceListLogic extends BaseGetXController { dismissEasyLoading(); }); BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -328,7 +329,7 @@ class FaceListLogic extends BaseGetXController { privateKey: getPrivateKeyList, token: getTokenList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); if (state.ifCurrentScreen.value == true) { diff --git a/star_lock/lib/main/lockDetail/fingerprint/addFingerprint/addFingerprint_logic.dart b/star_lock/lib/main/lockDetail/fingerprint/addFingerprint/addFingerprint_logic.dart index 7cb49484..dc1d0e0d 100644 --- a/star_lock/lib/main/lockDetail/fingerprint/addFingerprint/addFingerprint_logic.dart +++ b/star_lock/lib/main/lockDetail/fingerprint/addFingerprint/addFingerprint_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_type.dart'; @@ -264,8 +265,8 @@ class AddFingerprintLogic extends BaseGetXController { showBlueConnetctToastTimer(action: (){ Get.close(1); }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ cancelBlueConnetctToastTimer(); var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -291,7 +292,7 @@ class AddFingerprintLogic extends BaseGetXController { privateKey:getPrivateKeyList, token: getTokenList, ); - }else if (deviceConnectionState == DeviceConnectionState.disconnected){ + }else if (deviceConnectionState == BluetoothConnectionState.disconnected){ if(state.ifCurrentScreen.value == true){ showBlueConnetctToast(); } @@ -303,8 +304,8 @@ class AddFingerprintLogic extends BaseGetXController { // 添加胁迫指纹 Future senderAddStressFingerprint() async { - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); diff --git a/star_lock/lib/main/lockDetail/fingerprint/addFingerprintSelectType/addFingerprintType_page.dart b/star_lock/lib/main/lockDetail/fingerprint/addFingerprintSelectType/addFingerprintType_page.dart index 08e81b1d..37399952 100644 --- a/star_lock/lib/main/lockDetail/fingerprint/addFingerprintSelectType/addFingerprintType_page.dart +++ b/star_lock/lib/main/lockDetail/fingerprint/addFingerprintSelectType/addFingerprintType_page.dart @@ -119,7 +119,6 @@ class _AddFingerprintTypePageState extends State { String titleStr, String rightTitle, TextEditingController controller) { return Column( children: [ - Container(height: 10.h), CommonItem( leftTitel: titleStr, rightTitle: "", @@ -142,16 +141,12 @@ class _AddFingerprintTypePageState extends State { action: () async { Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { - setState(() { - setState(() { state.beginTime.value = - '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; + '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; state.beginTimeTimestamp.value = DateTime.parse(state.beginTime.value) .millisecondsSinceEpoch .toString(); - }); - }); }); })), Obx(() => CommonItem( @@ -161,16 +156,12 @@ class _AddFingerprintTypePageState extends State { action: () { Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { - setState(() { - setState(() { state.endTime.value = - '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; + '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; state.endTimeTimestamp.value = DateTime.parse(state.endTime.value) .millisecondsSinceEpoch .toString(); - }); - }); }); })), Container(height: 10.h), @@ -181,21 +172,21 @@ class _AddFingerprintTypePageState extends State { Widget keyBottomWidget() { return Column( children: [ - CommonItem( + Obx(() => CommonItem( leftTitel: "是否是管理员", rightTitle: "", isTipsImg: false, isHaveRightWidget: true, rightWidget: SizedBox( - width: 60.w, height: 50.h, child: _isAdmin())), + width: 60.w, height: 50.h, child: _isAdmin()))), SizedBox(height: 10.h), - CommonItem( + Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.stressFingerprint!.tr, rightTitle: "", isTipsImg: false, isHaveRightWidget: true, rightWidget: SizedBox( - width: 60.w, height: 50.h, child: _isStressFingerprint())), + width: 60.w, height: 50.h, child: _isStressFingerprint()))), SizedBox(height: 30.h), SubmitBtn( btnName: TranslationLoader.lanKeys!.next!.tr, @@ -339,9 +330,7 @@ class _AddFingerprintTypePageState extends State { thumbColor: CupertinoColors.white, value: state.isStressFingerprint.value, onChanged: (value) { - setState(() { - state.isStressFingerprint.value = value; - }); + state.isStressFingerprint.value = value; }, ); } @@ -354,9 +343,7 @@ class _AddFingerprintTypePageState extends State { thumbColor: CupertinoColors.white, value: state.isAdministrator.value, onChanged: (value) { - setState(() { - state.isAdministrator.value = value; - }); + state.isAdministrator.value = value; }, ); } diff --git a/star_lock/lib/main/lockDetail/fingerprint/fingerprintDetail/fingerprintDetail_logic.dart b/star_lock/lib/main/lockDetail/fingerprint/fingerprintDetail/fingerprintDetail_logic.dart index 27a7feea..958f5196 100644 --- a/star_lock/lib/main/lockDetail/fingerprint/fingerprintDetail/fingerprintDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/fingerprint/fingerprintDetail/fingerprintDetail_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -100,8 +101,8 @@ class FingerprintDetailLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -125,7 +126,7 @@ class FingerprintDetailLogic extends BaseGetXController{ privateKey:getPrivateKeyList, token: getTokenList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintList_logic.dart b/star_lock/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintList_logic.dart index 3185ddcf..4fa245be 100644 --- a/star_lock/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintList_logic.dart +++ b/star_lock/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintList_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../blue/blue_manage.dart'; @@ -239,8 +240,8 @@ class FingerprintListLogic extends BaseGetXController{ } // 获取指纹状态 Future senderQueryingFingerprintStatus() async { - BlueManage().bludSendData(BlueManage().connectDeviceName,(DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName,(BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -267,8 +268,8 @@ class FingerprintListLogic extends BaseGetXController{ // 查询用户、指纹、密码、卡片数量(用于判断是否同步) Future senderCheckingUserInfoCount() async { - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -298,8 +299,8 @@ class FingerprintListLogic extends BaseGetXController{ showBlueConnetctToastTimer(action: (){ dismissEasyLoading(); }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -321,7 +322,7 @@ class FingerprintListLogic extends BaseGetXController{ privateKey:getPrivateKeyList, token: getTokenList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); if(state.ifCurrentScreen.value == true){ diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index c9a4f0d5..0900fe5e 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; import 'dart:io'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:intl/intl.dart'; import 'package:permission_handler/permission_handler.dart'; @@ -92,6 +93,8 @@ class LockDetailLogic extends BaseGetXController { getLockRecordLastUploadDataTime(); state.openLockBtnState.value = 0; + + eventBus.fire(RefreshLockDetailInfoDataEvent()); break; case 0x06: @@ -270,6 +273,7 @@ class LockDetailLogic extends BaseGetXController { } lockRecordUploadData(uploadList); // print("reply.data:${reply.data} getList:$getList}"); + await BlueManage().disconnect(); } break; case 0x06: @@ -375,10 +379,9 @@ class LockDetailLogic extends BaseGetXController { eventBus.fire(RefreshLockDetailInfoDataEvent()); }); - BlueManage() - .bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, - (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, + (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { // 私钥 var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -408,7 +411,7 @@ class LockDetailLogic extends BaseGetXController { publicKey: publicKeyDataList, privateKey: getPrivateKeyList, token: getTokenList); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { cancelBlueConnetctToastTimer(); if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); @@ -436,7 +439,7 @@ class LockDetailLogic extends BaseGetXController { var token = await Storage.getStringList(saveBlueToken); List getTokenList = changeStringListToIntList(token!); - print("调用了开锁事件 openDoorTokenPubToken:$getTokenList getPrivateKeyList:$getPrivateKeyList"); + // print("调用了开锁事件 openDoorTokenPubToken:$getTokenList getPrivateKeyList:$getPrivateKeyList"); // ListlistData = await IoSenderManage.senderOpenLock( // keyID: BlueManage().connectDeviceName, // userID: await Storage.getUid(), @@ -450,8 +453,8 @@ class LockDetailLogic extends BaseGetXController { // ); BlueManage() .bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, - (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { IoSenderManage.senderOpenLock( keyID: BlueManage().connectDeviceName, userID: await Storage.getUid(), @@ -463,7 +466,7 @@ class LockDetailLogic extends BaseGetXController { signKey: signKeyDataList, privateKey: getPrivateKeyList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { cancelBlueConnetctToastTimer(); if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); @@ -564,8 +567,8 @@ class LockDetailLogic extends BaseGetXController { // 查询事件记录(时间查询) Future senderReferEventRecordTime(int time) async { BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart index 027a2a20..160a825e 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart @@ -850,9 +850,9 @@ class _LockDetailPageState extends State with TickerProviderStat } startOpenLock() { - print("11111111"); + // print("11111111"); // checkBlueIsOpen((){ - print("33333333"); + // print("33333333"); if (state.openLockBtnState.value == 1) { return; } @@ -911,9 +911,10 @@ class _LockDetailPageState extends State with TickerProviderStat AppRouteObserver().routeObserver.unsubscribe(this); state.closedUnlockSuccessfulTimer?.cancel(); _lockRefreshLockDetailInfoDataEvent?.cancel(); + if (state.animationController != null) { state.animationController!.dispose(); - // state.animationController = null; + state.animationController = null; } super.dispose(); } @@ -934,7 +935,7 @@ class _LockDetailPageState extends State with TickerProviderStat state.ifCurrentScreen.value = false; logic.cancelBlueConnetctToastTimer(); BlueManage().stopScan(); - BlueManage().disconnect(BlueManage().connectDeviceMacAddress); + BlueManage().disconnect(); state.openLockBtnState.value = 0; // if(state.animationController != null){ @@ -962,9 +963,9 @@ class _LockDetailPageState extends State with TickerProviderStat BlueManage().stopScan(); state.openLockBtnState.value = 0; - if (state.animationController!.isAnimating) { - state.animationController!.stop(); - } + // if (state.animationController!.isAnimating) { + // state.animationController!.stop(); + // } } } diff --git a/star_lock/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_logic.dart b/star_lock/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_logic.dart index b86c5c68..c8dcb612 100644 --- a/star_lock/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_logic.dart +++ b/star_lock/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyDetail/keyOperationRecord/keyOperationRecord_entity.dart'; import '../../../blue/blue_manage.dart'; @@ -156,8 +157,8 @@ class LockOperatingRecordLogic extends BaseGetXController { // 查询事件记录(时间查询) Future senderReferEventRecordTime(int time) async { BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); diff --git a/star_lock/lib/main/lockDetail/lockSet/automaticBlocking/automaticBlocking_logic.dart b/star_lock/lib/main/lockDetail/lockSet/automaticBlocking/automaticBlocking_logic.dart index b6a08b8c..e5ce3e24 100644 --- a/star_lock/lib/main/lockDetail/lockSet/automaticBlocking/automaticBlocking_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/automaticBlocking/automaticBlocking_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -133,32 +134,6 @@ class AutomaticBlockingLogic extends BaseGetXController{ } } - // 读取支持功能-带参数 - // Future _readSupportFunctionsWithParameters() async { - // BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - // if (connectionState == DeviceConnectionState.connected) { - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // - // var token = await Storage.getStringList(saveBlueToken); - // List getTokenList = changeStringListToIntList(token!); - // - // var publicKey = await Storage.getStringList(saveBluePublicKey); - // List getPublicKeyList = changeStringListToIntList(publicKey!); - // - // IoSenderManage.readSupportFunctionsWithParametersCommand( - // keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), - // userID: await Storage.getUid(), - // featureBit: 29, - // token: getTokenList, - // needAuthor: 1, - // publicKey: getPublicKeyList, - // privateKey: getPrivateKeyList - // ); - // } - // }); - // } - // 设置支持功能(带参数) Future sendAutoLock() async { if(state.sureBtnState.value == 1){ @@ -171,8 +146,8 @@ class AutomaticBlockingLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -203,7 +178,7 @@ class AutomaticBlockingLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_logic.dart b/star_lock/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_logic.dart index 084e257b..6764f3c5 100644 --- a/star_lock/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/blue/io_type.dart'; import '../../../../../blue/blue_manage.dart'; @@ -180,8 +181,8 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ showBlueConnetctToastTimer(action: (){ dismissEasyLoading(); }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -202,7 +203,7 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ publicKey: getPublicKeyList, privateKey: getPrivateKeyList ); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); if(state.ifCurrentScreen.value == true){ @@ -224,8 +225,8 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { var signKey = await Storage.getStringList(saveBlueSignKey); List signKeyDataList = changeStringListToIntList(signKey!); @@ -248,7 +249,7 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ signKey: signKeyDataList, privateKey: getPrivateKeyList, token: getTokenList); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { state.sureBtnState.value = 0; dismissEasyLoading(); cancelBlueConnetctToastTimer(); diff --git a/star_lock/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_logic.dart b/star_lock/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_logic.dart index 98a1e9a9..ca80fcad 100644 --- a/star_lock/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_logic.dart @@ -9,34 +9,6 @@ import 'basicInformation_state.dart'; class BasicInformationLogic extends BaseGetXController{ final BasicInformationState state = BasicInformationState(); - // 读取支持功能-带参数 - // Future _readAdminPassword() async { - // BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - // if (connectionState == DeviceConnectionState.connected) { - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // - // var token = await Storage.getStringList(saveBlueToken); - // List getTokenList = changeStringListToIntList(token!); - // - // var publicKey = await Storage.getStringList(saveBluePublicKey); - // List getPublicKeyList = changeStringListToIntList(publicKey!); - // - // IoSenderManage.senderReadAdminPasswordCommand( - // keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), - // userID: await Storage.getUid(), - // role:0xff, - // pwdNum:5, - // pwdNo: 0, - // token: getTokenList, - // needAuthor: 1, - // publicKey: getPublicKeyList, - // privateKey: getPrivateKeyList - // ); - // } - // }, isShowLoading: true); - // } - // 下级界面修改成功后传递数据 StreamSubscription? _passCurrentLockInformationEvent; void initLoadDataAction(BlockSetStateCallback blockSetStateCallback) { diff --git a/star_lock/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_logic.dart b/star_lock/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_logic.dart index 334be6da..2110ce23 100644 --- a/star_lock/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyDetail/keyOperationRecord/keyOperationRecord_entity.dart'; import '../../../../../blue/blue_manage.dart'; @@ -47,8 +48,8 @@ class UploadElectricQuantityLogic extends BaseGetXController { state.sureBtnState.value = 0; }); BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -57,7 +58,7 @@ class UploadElectricQuantityLogic extends BaseGetXController { userID: await Storage.getUid(), privateKey: getPrivateKeyList, ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart b/star_lock/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart index 9e00560a..ecc137bb 100644 --- a/star_lock/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart @@ -1,8 +1,9 @@ import 'dart:async'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsNoParameters.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -114,32 +115,6 @@ class BurglarAlarmLogic extends BaseGetXController{ } } - // 读取支持功能-带参数 - // Future _readSupportFunctionsNoParameters() async { - // BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - // if (connectionState == DeviceConnectionState.connected) { - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // - // var token = await Storage.getStringList(saveBlueToken); - // List getTokenList = changeStringListToIntList(token!); - // - // var publicKey = await Storage.getStringList(saveBluePublicKey); - // List getPublicKeyList = changeStringListToIntList(publicKey!); - // - // IoSenderManage.readSupportFunctionsNoParametersCommand( - // keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), - // userID: await Storage.getUid(), - // featureBit: 30, - // token: getTokenList, - // needAuthor: 1, - // publicKey: getPublicKeyList, - // privateKey: getPrivateKeyList - // ); - // } - // }); - // } - // 设置支持功能(带参数) Future sendBurglarAlarm() async { if(state.sureBtnState.value == 1){ @@ -152,8 +127,8 @@ class BurglarAlarmLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -172,7 +147,7 @@ class BurglarAlarmLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; @@ -183,31 +158,31 @@ class BurglarAlarmLogic extends BaseGetXController{ }); } - Timer? _timer; - // CancelableOperation? _operation; - void showBlueConnetctToastTimer({bool isShowBlueConnetctToast = true, Function? action}) { - if (_timer != null && _timer!.isActive) { - _timer!.cancel(); - _timer = null; - } - _timer = Timer.periodic(15.seconds, (timer) { - if (action != null) { - action(); - } - cancelBlueConnetctToastTimer(); - if (isShowBlueConnetctToast == true) { - showBlueConnetctToast(); - } - }); - } + // Timer? _timer; + // // CancelableOperation? _operation; + // void showBlueConnetctToastTimer({bool isShowBlueConnetctToast = true, Function? action}) { + // if (_timer != null && _timer!.isActive) { + // _timer!.cancel(); + // _timer = null; + // } + // _timer = Timer.periodic(15.seconds, (timer) { + // if (action != null) { + // action(); + // } + // cancelBlueConnetctToastTimer(); + // if (isShowBlueConnetctToast == true) { + // showBlueConnetctToast(); + // } + // }); + // } - void cancelBlueConnetctToastTimer() { - Get.log('cancelBlueConnetctToastTimer'); - if (_timer != null && _timer!.isActive) { - _timer!.cancel(); - _timer = null; - } - } + // void cancelBlueConnetctToastTimer() { + // Get.log('cancelBlueConnetctToastTimer'); + // if (_timer != null && _timer!.isActive) { + // _timer!.cancel(); + // _timer = null; + // } + // } @override void onReady() { diff --git a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart index 5df4a9c3..72f7d2ec 100644 --- a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart @@ -2,7 +2,8 @@ import 'dart:async'; import 'dart:io'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:network_info_plus/network_info_plus.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -150,8 +151,8 @@ class ConfiguringWifiLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected){ var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -204,7 +205,7 @@ class ConfiguringWifiLogic extends BaseGetXController{ publicKey: publicKeyDataList, privateKey: getPrivateKeyList, ); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart index 87507230..f80dacc2 100644 --- a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_protocol/io_getWifiList.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -97,8 +98,8 @@ class WifiListLogic extends BaseGetXController { dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected){ + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected){ var token = await Storage.getStringList(saveBlueToken); List getTokenList = changeStringListToIntList(token!); print("openDoorTokenPubToken:$getTokenList"); @@ -117,7 +118,7 @@ class WifiListLogic extends BaseGetXController { publicKey: publicKeyDataList, privateKey: getPrivateKeyList, ); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); state.sureBtnState.value = 0; cancelBlueConnetctToastTimer(); diff --git a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart index 0a7e28b0..ce029733 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart @@ -3,7 +3,9 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_protocol/io_deletUser.dart'; @@ -317,8 +319,8 @@ class LockSetLogic extends BaseGetXController { print("333333"); showDeletAlertTipDialog(); }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -336,7 +338,7 @@ class LockSetLogic extends BaseGetXController { publicKey: publicKeyDataList, privateKey: getPrivateKeyList, token: getTokenList); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); print("444444"); @@ -379,8 +381,8 @@ class LockSetLogic extends BaseGetXController { showBlueConnetctToastTimer(action: (){ dismissEasyLoading(); }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -415,7 +417,7 @@ class LockSetLogic extends BaseGetXController { needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); if(state.ifCurrentScreen.value == true){ @@ -522,16 +524,16 @@ class LockSetLogic extends BaseGetXController { }); } - late StreamSubscription>_scanListDiscoveredDeviceSubscription; - void _scanListDiscoveredDeviceSubscriptionAction() { - _scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on>().listen((List list) { - final knownDeviceIndex = list.indexWhere((d) => d.name == BlueManage().connectDeviceName); - if (knownDeviceIndex >= 0) { - // 存在的时候赋值 - state.currentDeviceUUid.value = (list[knownDeviceIndex].serviceUuids.isNotEmpty ? list[knownDeviceIndex].serviceUuids[0] : "").toString(); - } - }); - } + // late StreamSubscription>_scanListDiscoveredDeviceSubscription; + // void _scanListDiscoveredDeviceSubscriptionAction() { + // _scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on>().listen((List list) { + // final knownDeviceIndex = list.indexWhere((d) => d.name == BlueManage().connectDeviceName); + // if (knownDeviceIndex >= 0) { + // // 存在的时候赋值 + // state.currentDeviceUUid.value = (list[knownDeviceIndex].serviceUuids.isNotEmpty ? list[knownDeviceIndex].serviceUuids[0] : "").toString(); + // } + // }); + // } void showDeletAlertTipDialog({String? showContent = ""}) { // bool isContains = BlueManage().connectDeviceName!.contains("T9A"); @@ -643,7 +645,14 @@ class LockSetLogic extends BaseGetXController { void showDeletPasswordAlertDialog(BuildContext context) { // 点击删除 开始扫描 - BlueManage().startScan(); + // BlueManage().startScan(20, (List list) async { + // final knownDeviceIndex = list.indexWhere((d) => d.advertisementData.advName == BlueManage().connectDeviceName); + // if (knownDeviceIndex >= 0) { + // // 存在的时候赋值 + // state.currentDeviceUUid.value = (list[knownDeviceIndex].advertisementData.serviceUuids.isNotEmpty ? list[knownDeviceIndex].advertisementData.serviceUuids[0] : "").toString(); + // await BlueManage().stopScan(); + // } + // }); showDialog( context: context, builder: (BuildContext context) { @@ -661,7 +670,7 @@ class LockSetLogic extends BaseGetXController { }, cancelClick: () { // 取消的时候停止扫描 - BlueManage().stopScan(); + // BlueManage().stopScan(); Get.back(); }, ); @@ -724,7 +733,9 @@ class LockSetLogic extends BaseGetXController { if (entity.errorCode!.codeIsSuccessful) { Get.back(); - if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){ + factoryDataResetAction(); + + // if(BlueManage().bluetoothConnectionState == BluetoothConnectionState.connected){ // 如果是已连接状态 直接调用协议 // 已配对 表示这把锁未被初始化,还处于被添加状态 // if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) { @@ -740,86 +751,86 @@ class LockSetLogic extends BaseGetXController { // deletKeyData(); // } // } - return; - } - - if (state.currentDeviceUUid.value.isNotEmpty) { - // 已经扫描到了当前设备 停止扫描,直接删除锁 - BlueManage().stopScan(); - deletLockLogic(); - } else { - // 未扫描到 然后循环5秒扫秒 - var index = 0; - showEasyLoading(); - state.deletWaitScanCompleter = Completer(); - state.deletWaitScanTimer = Timer.periodic(const Duration(seconds: 1), (timer) { - //定时任务 - if(index >= 7){ - // 当超过10秒的时候还是没有搜索到,完成任务,关闭扫描,取消定时器,弹窗提示 - if (state.deletWaitScanTimer != null && state.deletWaitScanTimer!.isActive) { - state.deletWaitScanTimer!.cancel(); - state.deletWaitScanTimer = null; - } - if(state.deletWaitScanCompleter != null){ - state.deletWaitScanCompleter!.complete(); - } - BlueManage().stopScan(); - dismissEasyLoading(); - print("555555"); - showDeletAlertTipDialog(); - }else{ - // 每秒判断获取是否搜到了当前设备 - if (state.currentDeviceUUid.isNotEmpty) { - BlueManage().stopScan(); - // 存在的时候销毁定时器,赋值 - if (state.deletWaitScanTimer != null && state.deletWaitScanTimer!.isActive) { - state.deletWaitScanTimer!.cancel(); - state.deletWaitScanTimer = null; - } - if(state.deletWaitScanCompleter != null){ - state.deletWaitScanCompleter!.complete(); - } - dismissEasyLoading(); - - deletLockLogic(); - } else { - // 不存在的时候返回-1 然后循环5秒 - index++; - // print("index:$index"); - } - } - }); - // 等待Completer完成 - await state.deletWaitScanCompleter!.future; - } + // return; + // } + // print("state.currentDeviceUUid.value:${state.currentDeviceUUid.value}"); + // if (state.currentDeviceUUid.value.isNotEmpty) { + // // 已经扫描到了当前设备 停止扫描,直接删除锁 + // // BlueManage().stopScan(); + // deletLockLogic(); + // } else { + // // 未扫描到 然后循环5秒扫秒 + // var index = 0; + // showEasyLoading(); + // state.deletWaitScanCompleter = Completer(); + // state.deletWaitScanTimer = Timer.periodic(const Duration(seconds: 1), (timer) { + // //定时任务 + // if(index >= 7){ + // // 当超过10秒的时候还是没有搜索到,完成任务,关闭扫描,取消定时器,弹窗提示 + // if (state.deletWaitScanTimer != null && state.deletWaitScanTimer!.isActive) { + // state.deletWaitScanTimer!.cancel(); + // state.deletWaitScanTimer = null; + // } + // if(state.deletWaitScanCompleter != null){ + // state.deletWaitScanCompleter!.complete(); + // } + // // BlueManage().stopScan(); + // dismissEasyLoading(); + // print("555555"); + // showDeletAlertTipDialog(); + // }else{ + // // 每秒判断获取是否搜到了当前设备 + // if (state.currentDeviceUUid.isNotEmpty) { + // // BlueManage().stopScan(); + // // 存在的时候销毁定时器,赋值 + // if (state.deletWaitScanTimer != null && state.deletWaitScanTimer!.isActive) { + // state.deletWaitScanTimer!.cancel(); + // state.deletWaitScanTimer = null; + // } + // if(state.deletWaitScanCompleter != null){ + // state.deletWaitScanCompleter!.complete(); + // } + // dismissEasyLoading(); + // + // deletLockLogic(); + // } else { + // // 不存在的时候返回-1 然后循环5秒 + // index++; + // // print("index:$index"); + // } + // } + // }); + // // 等待Completer完成 + // await state.deletWaitScanCompleter!.future; + // } } } // 已经扫描到了当前设备 停止扫描,直接调用删除锁逻辑 - void deletLockLogic() { - // 当扫描的数组里面是否有当前设备 - if(state.currentDeviceUUid.value[31] == "1"){ - // 已配对 表示这把锁未被初始化,还处于被添加状态 - // if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) { - // 如果是锁拥有者直接删除锁,调用初始化协议 - factoryDataResetAction(); - // } else { - // // 不是锁拥有者 - // if(state.lockSetInfoData.value.lockBasicInfo!.lockUserNo != 0){ - // // 如果已经创建了用户调用协议删除 - // deletUserAction(); - // }else{ - // // 如果没有创建用户 调用接口删除 - // deletKeyData(); - // } - // } - }else if(state.currentDeviceUUid.value[31] == "0"){ - // 未配对 表示这把锁已被强制初始化 处于可添加状态 直接弹窗删除即可 - print("666666"); - // showDeletAlertTipDialog(showContent:"当前锁已被强制初始化,可直接添加。"); - deletLockInfoData(); - } - } + // void deletLockLogic() { + // // 当扫描的数组里面是否有当前设备 + // if(state.currentDeviceUUid.value[31] == "1"){ + // // 已配对 表示这把锁未被初始化,还处于被添加状态 + // // if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) { + // // 如果是锁拥有者直接删除锁,调用初始化协议 + // factoryDataResetAction(); + // // } else { + // // // 不是锁拥有者 + // // if(state.lockSetInfoData.value.lockBasicInfo!.lockUserNo != 0){ + // // // 如果已经创建了用户调用协议删除 + // // deletUserAction(); + // // }else{ + // // // 如果没有创建用户 调用接口删除 + // // deletKeyData(); + // // } + // // } + // }else if(state.currentDeviceUUid.value[31] == "0"){ + // // 未配对 表示这把锁已被强制初始化 处于可添加状态 直接弹窗删除即可 + // print("666666"); + // // showDeletAlertTipDialog(showContent:"当前锁已被强制初始化,可直接添加。"); + // deletLockInfoData(); + // } + // } // 当是锁拥有者的时候,删除锁 void deletLockInfoData() async { @@ -837,7 +848,7 @@ class LockSetLogic extends BaseGetXController { }); }else{ Future.delayed(const Duration(milliseconds: 200)).then((e) { - Get.close(2); + Get.back(); }); } } @@ -874,7 +885,7 @@ class LockSetLogic extends BaseGetXController { super.onReady(); _initReplySubscription(); - _scanListDiscoveredDeviceSubscriptionAction(); + // _scanListDiscoveredDeviceSubscriptionAction(); } @override @@ -889,6 +900,6 @@ class LockSetLogic extends BaseGetXController { _replySubscription.cancel(); _passCurrentLockInformationEvent!.cancel(); - _scanListDiscoveredDeviceSubscription.cancel(); + // _scanListDiscoveredDeviceSubscription.cancel(); } } diff --git a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart index 6c0116ac..34a022c2 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart @@ -778,7 +778,7 @@ class _LockSetPageState extends State with RouteAware { !state.deletWaitScanCompleter!.isCompleted) { state.deletWaitScanCompleter!.complete(); } - BlueManage().stopScan(); + // BlueManage().stopScan(); state.ifCurrentScreen.value = false; } @@ -805,7 +805,7 @@ class _LockSetPageState extends State with RouteAware { !state.deletWaitScanCompleter!.isCompleted) { state.deletWaitScanCompleter!.complete(); } - BlueManage().stopScan(); + // BlueManage().stopScan(); state.ifCurrentScreen.value = false; } } diff --git a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_state.dart b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_state.dart index 0e56a966..b4f7a48c 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_state.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_state.dart @@ -17,7 +17,7 @@ class LockSetState { var isOnlyOneData = false.obs; var isAttendance = 0.obs;// 是否开启考勤 - var currentDeviceUUid = "".obs;// 当前设备的uuid + // var currentDeviceUUid = "".obs;// 当前设备的uuid var isOpenLockNeedOnline = 0.obs;// APP开锁时是否需联网 var isLockPickingReminder = 0.obs;// 是否开启开锁提醒 diff --git a/star_lock/lib/main/lockDetail/lockSet/lockSoundSet/lockSoundSet_logic.dart b/star_lock/lib/main/lockDetail/lockSet/lockSoundSet/lockSoundSet_logic.dart index 03bebe5a..fc2aa74e 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockSoundSet/lockSoundSet_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockSoundSet/lockSoundSet_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../blue/blue_manage.dart'; @@ -120,32 +121,6 @@ class LockSoundSetLogic extends BaseGetXController { } } - // 读取支持功能-带参数 - // Future _readSupportFunctionsWithParameters() async { - // BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - // if (connectionState == DeviceConnectionState.connected) { - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // - // var token = await Storage.getStringList(saveBlueToken); - // List getTokenList = changeStringListToIntList(token!); - // - // var publicKey = await Storage.getStringList(saveBluePublicKey); - // List getPublicKeyList = changeStringListToIntList(publicKey!); - // - // IoSenderManage.readSupportFunctionsWithParametersCommand( - // keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), - // userID: await Storage.getUid(), - // featureBit: 33, - // token: getTokenList, - // needAuthor: 1, - // publicKey: getPublicKeyList, - // privateKey: getPrivateKeyList - // ); - // } - // }); - // } - // 设置支持功能(带参数) Future sendLockSound() async { if(state.sureBtnState.value == 1){ @@ -158,8 +133,8 @@ class LockSoundSetLogic extends BaseGetXController { dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -187,7 +162,7 @@ class LockSoundSetLogic extends BaseGetXController { needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart b/star_lock/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart index 072a40c2..a4b1352e 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; + +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import '../../../../blue/blue_manage.dart'; import '../../../../blue/io_protocol/io_timing.dart'; @@ -126,22 +127,6 @@ class LockTimeLogic extends BaseGetXController{ } } - // 获取锁状态 - // Future _getLockStatus() async { - // // 进来之后首先连接 - // BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async { - // if (state == DeviceConnectionState.connected) { - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // IoSenderManage.senderGetLockStatu( - // lockID:BlueManage().connectDeviceName, - // userID:await Storage.getUid(), - // privateKey:getPrivateKeyList, - // ); - // } - // }, isShowLoading: false); - // } - // 校验时间 Future sendTiming() async { if(state.sureBtnState.value == 1){ @@ -154,8 +139,8 @@ class LockTimeLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -174,7 +159,7 @@ class LockTimeLogic extends BaseGetXController{ signKey:getSignKeyList, privateKey:getPrivateKeyList, ); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/lockSet/motorPower/motorPower_logic.dart b/star_lock/lib/main/lockDetail/lockSet/motorPower/motorPower_logic.dart index b36dbcf5..d4beaa98 100644 --- a/star_lock/lib/main/lockDetail/lockSet/motorPower/motorPower_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/motorPower/motorPower_logic.dart @@ -1,7 +1,9 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; + +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import '../../../../blue/blue_manage.dart'; import '../../../../blue/io_protocol/io_setSupportFunctionsNoParameters.dart'; @@ -109,8 +111,8 @@ class MotorPowerLogic extends BaseGetXController { // 读取支持功能-带参数 Future _readSupportFunctionsNoParameters() async { - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -135,8 +137,8 @@ class MotorPowerLogic extends BaseGetXController { // 设置支持功能(带参数) Future sendOpenDoorDirection() async { - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); diff --git a/star_lock/lib/main/lockDetail/lockSet/normallyOpenMode/normallyOpenMode_logic.dart b/star_lock/lib/main/lockDetail/lockSet/normallyOpenMode/normallyOpenMode_logic.dart index 1ed9f9b8..c8ecb09a 100644 --- a/star_lock/lib/main/lockDetail/lockSet/normallyOpenMode/normallyOpenMode_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/normallyOpenMode/normallyOpenMode_logic.dart @@ -1,7 +1,7 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../blue/blue_manage.dart'; @@ -139,32 +139,6 @@ class NormallyOpenModeLogic extends BaseGetXController{ } } - // 读取支持功能-带参数 - // Future _readSupportFunctionsWithParameters() async { - // BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - // if (connectionState == DeviceConnectionState.connected) { - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // - // var token = await Storage.getStringList(saveBlueToken); - // List getTokenList = changeStringListToIntList(token!); - // - // var publicKey = await Storage.getStringList(saveBluePublicKey); - // List getPublicKeyList = changeStringListToIntList(publicKey!); - // - // IoSenderManage.readSupportFunctionsWithParametersCommand( - // keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), - // userID: await Storage.getUid(), - // featureBit: 50, - // token: getTokenList, - // needAuthor: 1, - // publicKey: getPublicKeyList, - // privateKey: getPrivateKeyList - // ); - // } - // }); - // } - // 设置支持功能(带参数) Future sendAutoLock() async { if(state.sureBtnState.value == 1){ @@ -177,8 +151,8 @@ class NormallyOpenModeLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -230,7 +204,7 @@ class NormallyOpenModeLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/lockSet/openDoorDirection/openDoorDirection_logic.dart b/star_lock/lib/main/lockDetail/lockSet/openDoorDirection/openDoorDirection_logic.dart index ea5d7997..b51e6950 100644 --- a/star_lock/lib/main/lockDetail/lockSet/openDoorDirection/openDoorDirection_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/openDoorDirection/openDoorDirection_logic.dart @@ -1,7 +1,9 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; + +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import '../../../../blue/blue_manage.dart'; import '../../../../blue/io_protocol/io_setSupportFunctionsNoParameters.dart'; @@ -109,38 +111,12 @@ class OpenDoorDirectionLogic extends BaseGetXController { } } - // 读取支持功能-带参数 - // Future _readSupportFunctionsNoParameters() async { - // BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - // if (connectionState == DeviceConnectionState.connected) { - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // - // var token = await Storage.getStringList(saveBlueToken); - // List getTokenList = changeStringListToIntList(token!); - // - // var publicKey = await Storage.getStringList(saveBluePublicKey); - // List getPublicKeyList = changeStringListToIntList(publicKey!); - // - // IoSenderManage.readSupportFunctionsNoParametersCommand( - // keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), - // userID: await Storage.getUid(), - // featureBit: 41, - // token: getTokenList, - // needAuthor: 1, - // publicKey: getPublicKeyList, - // privateKey: getPrivateKeyList - // ); - // } - // }); - // } - // 设置支持功能(带参数) Future sendOpenDoorDirection() async { showEasyLoading(); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { dismissEasyLoading(); - if (connectionState == DeviceConnectionState.connected) { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -159,7 +135,7 @@ class OpenDoorDirectionLogic extends BaseGetXController { needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); - }else if (connectionState == DeviceConnectionState.disconnected) { + }else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); showBlueConnetctToast(); } diff --git a/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart b/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart index 3defb3ae..3050d41a 100644 --- a/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../blue/blue_manage.dart'; @@ -111,32 +112,6 @@ class RemoteUnlockingLogic extends BaseGetXController{ } } - // 读取支持功能-带参数 - // Future _readSupportFunctionsNoParameters() async { - // BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - // if (connectionState == DeviceConnectionState.connected) { - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // - // var token = await Storage.getStringList(saveBlueToken); - // List getTokenList = changeStringListToIntList(token!); - // - // var publicKey = await Storage.getStringList(saveBluePublicKey); - // List getPublicKeyList = changeStringListToIntList(publicKey!); - // - // IoSenderManage.readSupportFunctionsNoParametersCommand( - // keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), - // userID: await Storage.getUid(), - // featureBit: 28, - // token: getTokenList, - // needAuthor: 1, - // publicKey: getPublicKeyList, - // privateKey: getPrivateKeyList - // ); - // } - // }); - // } - // 设置支持功能(带参数) 远程开锁 Future sendBurglarAlarm() async { if(state.sureBtnState.value == 1){ @@ -149,8 +124,8 @@ class RemoteUnlockingLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -169,7 +144,7 @@ class RemoteUnlockingLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/lockSet/resetButton/resetButton_logic.dart b/star_lock/lib/main/lockDetail/lockSet/resetButton/resetButton_logic.dart index fe76ca7a..a5468fa1 100644 --- a/star_lock/lib/main/lockDetail/lockSet/resetButton/resetButton_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/resetButton/resetButton_logic.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/main/lockDetail/lockSet/resetButton/resetButton_state.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -112,32 +113,6 @@ class ResetButtonLogic extends BaseGetXController{ } } - // 读取支持功能-带参数 - // Future _readSupportFunctionsNoParameters() async { - // BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - // if (connectionState == DeviceConnectionState.connected) { - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // - // var token = await Storage.getStringList(saveBlueToken); - // List getTokenList = changeStringListToIntList(token!); - // - // var publicKey = await Storage.getStringList(saveBluePublicKey); - // List getPublicKeyList = changeStringListToIntList(publicKey!); - // - // IoSenderManage.readSupportFunctionsNoParametersCommand( - // keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), - // userID: await Storage.getUid(), - // featureBit: 31, - // token: getTokenList, - // needAuthor: 1, - // publicKey: getPublicKeyList, - // privateKey: getPrivateKeyList - // ); - // } - // }); - // } - // 设置支持功能(带参数) Future sendBurglarAlarm() async { if(state.sureBtnState.value == 1){ @@ -150,8 +125,8 @@ class ResetButtonLogic extends BaseGetXController{ dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -170,7 +145,7 @@ class ResetButtonLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); - } else if (connectionState == DeviceConnectionState.disconnected) { + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart index 9dc89753..dee82c05 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart'; import 'package:star_lock/network/api_repository.dart'; @@ -246,8 +247,8 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { var signKey = await Storage.getStringList(saveBlueSignKey); List signKeyDataList = changeStringListToIntList(signKey!); @@ -261,8 +262,8 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { IoSenderManage.senderCustomPasswordsCommand( keyID: "1", userID: await Storage.getUid(), - pwdNo: 1, - pwd:state.pwdController.text, + pwdNo: state.isAdministrator.value == true ? 254 : 1, + pwd: state.pwdController.text, useCountLimit: 0xff, startTime: 0x11223344, endTime: 0x11223344, @@ -270,7 +271,7 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { signKey: signKeyDataList, privateKey: getPrivateKeyList, token: getTokenList); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart index 982c858d..26ca31b5 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart @@ -76,6 +76,7 @@ class _PasswordKeyPerpetualPageState extends State wit return Column( children: [ perpetualKeyWidget( + false, TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, state.nameController), @@ -90,6 +91,7 @@ class _PasswordKeyPerpetualPageState extends State wit children: [ keyTimeLimitWidget(), perpetualKeyWidget( + false, TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, state.nameController), @@ -103,6 +105,7 @@ class _PasswordKeyPerpetualPageState extends State wit return Column( children: [ perpetualKeyWidget( + false, TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, state.nameController), @@ -120,11 +123,16 @@ class _PasswordKeyPerpetualPageState extends State wit ? keyTimeLimitWidget() : Container(), perpetualKeyWidget( + false, TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, state.nameController), - perpetualKeyWidget(TranslationLoader.lanKeys!.password!.tr, - "请输入6-9位数字", state.pwdController), + perpetualKeyWidget( + false, + TranslationLoader.lanKeys!.password!.tr, + "请输入6-9位数字", state.pwdController + ), + keyIfAdministratorWidget(), keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip4!.tr) ], ); @@ -136,6 +144,7 @@ class _PasswordKeyPerpetualPageState extends State wit children: [ keyCirculationWidget(), perpetualKeyWidget( + true, TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, state.nameController), @@ -149,6 +158,7 @@ class _PasswordKeyPerpetualPageState extends State wit return Column( children: [ perpetualKeyWidget( + false, TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, state.nameController), @@ -164,10 +174,10 @@ class _PasswordKeyPerpetualPageState extends State wit // 密码命名输入框 Widget perpetualKeyWidget( - String titleStr, String rightTitle, TextEditingController controller) { + bool isTopHeight, String titleStr, String rightTitle, TextEditingController controller) { return Column( children: [ - SizedBox(height: 10.h), + isTopHeight ? SizedBox(height: 10.h) : Container(), CommonItem( leftTitel: titleStr, rightTitle: "", @@ -243,8 +253,7 @@ class _PasswordKeyPerpetualPageState extends State wit leftTitel: TranslationLoader.lanKeys!.permanent!.tr, rightTitle: "", isHaveRightWidget: true, - rightWidget: SizedBox(width: 60.w, height: 50.h, child: _switch()), - action: () {}), + rightWidget: SizedBox(width: 60.w, height: 50.h, child: _switch())), state.isPermanent.value == true ? Container(height: 10.h) : Container(height: 1.h), @@ -252,6 +261,23 @@ class _PasswordKeyPerpetualPageState extends State wit ); } + // 自定义是否永久 + Widget keyIfAdministratorWidget() { + return Column( + children: [ + // SizedBox(height: 10.h), + Obx(() => CommonItem( + leftTitel: "是否是管理员", + rightTitle: "", + isTipsImg: false, + isHaveRightWidget: true, + rightWidget: SizedBox( + width: 60.w, height: 50.h, child: _isAdministrator()))), + SizedBox(height: 10.h), + ], + ); + } + // 循环 Widget keyCirculationWidget() { return Column( @@ -591,6 +617,19 @@ class _PasswordKeyPerpetualPageState extends State wit ); } + // 是否是管理员 + CupertinoSwitch _isAdministrator() { + return CupertinoSwitch( + activeColor: CupertinoColors.activeBlue, + trackColor: CupertinoColors.systemGrey5, + thumbColor: CupertinoColors.white, + value: state.isAdministrator.value, + onChanged: (value) { + state.isAdministrator.value = value; + }, + ); + } + String intToStr(int v) { return (v < 10) ? "0$v" : "$v"; } diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart index a97cbb4d..27f63f7e 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart @@ -12,6 +12,7 @@ class PasswordKeyPerpetualState { final isPermanent = true.obs; //是否永久 var getPwdStr = ''.obs; var pwdNameStr = ''; + final isAdministrator = false.obs;// 是否是管理员 final effectiveDateTime = DateTime.now().obs; final failureDateTime = DateTime.now().obs; diff --git a/star_lock/lib/main/lockMian/lockMain/lockMain_logic.dart b/star_lock/lib/main/lockMian/lockMain/lockMain_logic.dart index 75a15c99..e11e1cc4 100644 --- a/star_lock/lib/main/lockMian/lockMain/lockMain_logic.dart +++ b/star_lock/lib/main/lockMian/lockMain/lockMain_logic.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:connectivity_plus/connectivity_plus.dart'; +import '../../../blue/blue_manage.dart'; import '../../../network/api_repository.dart'; import '../../../talk/udp/udp_help.dart'; import '../../../tools/baseGetXController.dart'; @@ -85,6 +86,8 @@ class LockMainLogic extends BaseGetXController { // 开启UDP UdpHelp().openUDP(); + + BlueManage(); } @override diff --git a/star_lock/lib/mine/addLock/lockAddress/gaode/lockAddressGaoDe_page.dart b/star_lock/lib/mine/addLock/lockAddress/gaode/lockAddressGaoDe_page.dart index 0335db75..91f1caa9 100644 --- a/star_lock/lib/mine/addLock/lockAddress/gaode/lockAddressGaoDe_page.dart +++ b/star_lock/lib/mine/addLock/lockAddress/gaode/lockAddressGaoDe_page.dart @@ -386,7 +386,7 @@ class _LockAddressGaoDePageState extends State with RouteA AppRouteObserver().routeObserver.unsubscribe(this); super.dispose(); - BlueManage().disconnect(BlueManage().connectDeviceMacAddress); + BlueManage().disconnect(); location.stopLocation(); location.destroy(); diff --git a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart index 505a0739..b46e508b 100644 --- a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart +++ b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_protocol/io_getPrivateKey.dart'; import 'package:star_lock/blue/io_protocol/io_getPublicKey.dart'; @@ -22,10 +23,10 @@ class NearbyLockLogic extends BaseGetXController { // 点击连接设备 void connect(String deviceName){ showEasyLoading(); - BlueManage().bludSendData(deviceName, (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + BlueManage().bludSendData(deviceName, (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { IoSenderManage.getPublicKey(lockId: deviceName); - }else if (state == DeviceConnectionState.disconnected) { + }else if (state == BluetoothConnectionState.disconnected) { dismissEasyLoading(); // showBlueConnetctToast(); } @@ -175,9 +176,9 @@ class NearbyLockLogic extends BaseGetXController { // 厂商序列号 var serialNum0 = reply.data.sublist(84, 100); var serialNum0Str = utf8String(serialNum0); - // state.lockInfo["serialNum0"] = serialNum0Str; - state.lockInfo["serialNum0"] = "${DateTime.now().millisecondsSinceEpoch ~/ 10}"; - // print("serialNum0Str:$serialNum0Str serialNum0Str:${serialNum0Str.length}"); + state.lockInfo["serialNum0"] = serialNum0Str; + // state.lockInfo["serialNum0"] = "${DateTime.now().millisecondsSinceEpoch ~/ 10}"; + print("serialNum0Str:$serialNum0Str serialNum0Str:${serialNum0Str.length}"); // 成品商序列号 var serialNum1 = reply.data.sublist(100, 116); @@ -239,6 +240,11 @@ class NearbyLockLogic extends BaseGetXController { var featureValueLength = reply.data[173]; // 锁特征值说明(本机能支持的功能) // 获取到锁给的字符数组 + var featureNetxLength = index + featureValueLength + 1; + if(reply.data.length < featureNetxLength){ + showToast("锁特征值数据获取失败,请重新点击获取"); + return; + } var featureValue = reply.data.sublist(index + 1, index + featureValueLength + 1); String featureValueStr = asciiString(featureValue); state.featureValue = featureValueStr; @@ -249,6 +255,11 @@ class NearbyLockLogic extends BaseGetXController { // 使能特征值字符串长度 var featureEnValLength = reply.data[index]; // 使能锁特征值说明(本机启用的功能) + var featureEnNextLength = index + featureEnValLength + 1; + if(reply.data.length < featureEnNextLength){ + showToast("锁使能特征值数据获取失败,请重新点击获取"); + return; + } var featureEnVal = reply.data.sublist(index + 1, index + featureEnValLength + 1); String featureEnValStr = asciiString(featureEnVal); state.featureSettingValue = featureEnValStr; @@ -315,8 +326,8 @@ class NearbyLockLogic extends BaseGetXController { Future _getStarLockStatus() async { // print("connectDeviceMacAddress:${BlueManage().connectDeviceMacAddress} connectDeviceName:${BlueManage().connectDeviceName}"); // 进来之后首先连接 - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.connected) { dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -330,31 +341,39 @@ class NearbyLockLogic extends BaseGetXController { userID: await Storage.getUid(), privateKey: getPrivateKeyList, ); - } else if (state == DeviceConnectionState.disconnected) { + } else if (state == BluetoothConnectionState.disconnected) { dismissEasyLoading(); } }, isAddEquipment: true); } - late StreamSubscription>_scanListDiscoveredDeviceSubscription; - void _scanListDiscoveredDeviceSubscriptionAction() { - _scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on>().listen((List list) { + // late StreamSubscription>_scanListDiscoveredDeviceSubscription; + // void _scanListDiscoveredDeviceSubscriptionAction() { + // _scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on>().listen((List list) { + // state.devices.clear(); + // for (int i = 0; i < list.length; i++) { + // ScanResult device = list[i]; + // if (((device.advertisementData.serviceUuids.isNotEmpty ? device.advertisementData.serviceUuids[0] : "").toString()[31] != "1")) { + // state.devices.add(list[i]); + // } + // } + // }); + // } + + void startScanBlueList(){ + BlueManage().startScan(2000, (List list){ state.devices.clear(); for (int i = 0; i < list.length; i++) { - DiscoveredDevice device = list[i]; - if (((device.serviceUuids.isNotEmpty ? device.serviceUuids[0] : "").toString()[31] != "1")) { + ScanResult device = list[i]; + if (((device.advertisementData.serviceUuids.isNotEmpty ? device.advertisementData.serviceUuids[0] : "").toString()[31] != "1")) { state.devices.add(list[i]); } } }); } - void startScanBlueList(){ - BlueManage().startScan(); - } - void stopScanBlueList(){ - BlueManage().disconnect("state.selectLockName.value"); + BlueManage().disconnect(); BlueManage().stopScan(); } @@ -365,9 +384,10 @@ class NearbyLockLogic extends BaseGetXController { print("NearbyLockLogic onReady()"); _initReplySubscription(); - _scanListDiscoveredDeviceSubscriptionAction(); + // _scanListDiscoveredDeviceSubscriptionAction(); state.ifCurrentScreen.value = true; + startScanBlueList(); } @@ -383,6 +403,6 @@ class NearbyLockLogic extends BaseGetXController { // TODO: implement onClose super.onClose(); _replySubscription.cancel(); - _scanListDiscoveredDeviceSubscription.cancel(); + // _scanListDiscoveredDeviceSubscription.cancel(); } } diff --git a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart index c9469477..5917c739 100644 --- a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart +++ b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart @@ -4,12 +4,14 @@ import 'dart:typed_data'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import '../../../appRouters.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'; @@ -55,9 +57,9 @@ class _NearbyLockPageState extends State with RouteAware { return nearbyLockItem('images/icon_lockGroup_item.png', state.devices[index], () { // Navigator.pushNamed(context, Routers.lockAddressPage); // logic.getPublicKey(state.devices[index].serviceUuids[0].toString()); - state.selectLockName.value = state.devices[index].name; + state.selectLockName.value = state.devices[index].advertisementData.advName; // print("connect-lockId:${state.devices[index].id} deviceName:${state.devices[index].name}"); - logic.connect(state.devices[index].name); + logic.connect(state.devices[index].advertisementData.advName); // Get.toNamed(Routers.lockAddressGaoDePage); }); }, @@ -74,9 +76,9 @@ class _NearbyLockPageState extends State with RouteAware { ); } - Widget nearbyLockItem(String lockTypeIcon, DiscoveredDevice discoveredDevice, Function() action ) { + Widget nearbyLockItem(String lockTypeIcon, ScanResult scanResult, Function() action ) { return GestureDetector( - onTap: ((discoveredDevice.serviceUuids.isNotEmpty ? discoveredDevice.serviceUuids[0] : "").toString()[33] == "1") ? action : null, + onTap: ((scanResult.advertisementData.serviceUuids.isNotEmpty ? scanResult.advertisementData.serviceUuids[0] : "").toString()[33] == "1") ? action : null, child: Column( // mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -98,7 +100,7 @@ class _NearbyLockPageState extends State with RouteAware { crossAxisAlignment: CrossAxisAlignment.start, children: [ // 第32、33两位00 表示休眠, 01表示唤醒 - Text(discoveredDevice.name, style: TextStyle(fontSize: 20.sp, color: ((discoveredDevice.serviceUuids.isNotEmpty ? discoveredDevice.serviceUuids[0] : "").toString()[33] == "1") ? AppColors.blackColor : Colors.grey)), + Text(scanResult.advertisementData.advName, style: TextStyle(fontSize: 20.sp, color: ((scanResult.advertisementData.serviceUuids.isNotEmpty ? scanResult.advertisementData.serviceUuids[0] : "").toString()[33] == "1") ? AppColors.blackColor : Colors.grey)), ], ), SizedBox( @@ -163,6 +165,7 @@ class _NearbyLockPageState extends State with RouteAware { state.ifCurrentScreen.value = false; logic.cancelBlueConnetctToastTimer(); logic.stopScanBlueList(); + BlueManage().disconnect(); } /// 从下级返回 当前界面即将出现 @@ -184,6 +187,7 @@ class _NearbyLockPageState extends State with RouteAware { state.ifCurrentScreen.value = false; logic.cancelBlueConnetctToastTimer(); logic.stopScanBlueList(); + BlueManage().disconnect(); } } diff --git a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_state.dart b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_state.dart index 5331c5c2..984ba280 100644 --- a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_state.dart +++ b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_state.dart @@ -1,12 +1,13 @@ import 'dart:typed_data'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; class NearbyLockState { - RxList devices = [].obs; + RxList devices = [].obs; var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 var selectLockName = "".obs; diff --git a/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart b/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart index 822d8f5b..720e3d93 100644 --- a/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart +++ b/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart @@ -3,7 +3,8 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_protocol/io_changeAdministratorPassword.dart'; import 'package:star_lock/blue/io_protocol/io_senderCustomPasswords.dart'; @@ -234,9 +235,9 @@ class SaveLockLogic extends BaseGetXController { dismissEasyLoading(); state.saveBtnIsUsable.value = true; }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { // print("222222"); - if (deviceConnectionState == DeviceConnectionState.connected){ + if (deviceConnectionState == BluetoothConnectionState.connected){ // print("333333"); // 私钥 var privateKey = await Storage.getStringList(saveBluePrivateKey); @@ -267,7 +268,7 @@ class SaveLockLogic extends BaseGetXController { privateKey:getPrivateKeyList, token: getTokenList ); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { print("444444"); dismissEasyLoading(); cancelBlueConnetctToastTimer(); @@ -285,8 +286,8 @@ class SaveLockLogic extends BaseGetXController { var number = rng.nextInt(900000) + 100000; // 生成 100000 到 999999 之间的随机整数 state.adminPassword = number.toString(); state.adminPasswordTF.text = number.toString(); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { var signKey = await Storage.getStringList(saveBlueSignKey); List signKeyDataList = changeStringListToIntList(signKey!); @@ -319,8 +320,8 @@ class SaveLockLogic extends BaseGetXController { showBlueConnetctToastTimer(action: (){ dismissEasyLoading(); }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { var signKey = await Storage.getStringList(saveBlueSignKey); List signKeyDataList = changeStringListToIntList(signKey!); @@ -343,7 +344,7 @@ class SaveLockLogic extends BaseGetXController { signKey: signKeyDataList, privateKey: getPrivateKeyList, token: getTokenList); - } else if (deviceConnectionState == DeviceConnectionState.disconnected) { + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { print("444444"); dismissEasyLoading(); cancelBlueConnetctToastTimer(); @@ -459,7 +460,7 @@ class SaveLockLogic extends BaseGetXController { } void backAction(){ - BlueManage().disconnect(BlueManage().connectDeviceMacAddress); + BlueManage().disconnect(); Get.close(state.isFromMap == 1 ? 6 : 7); } diff --git a/star_lock/lib/mine/mineSet/mineSet/mineSet_logic.dart b/star_lock/lib/mine/mineSet/mineSet/mineSet_logic.dart index c8bb8277..60f0d570 100644 --- a/star_lock/lib/mine/mineSet/mineSet/mineSet_logic.dart +++ b/star_lock/lib/mine/mineSet/mineSet/mineSet_logic.dart @@ -54,7 +54,7 @@ class MineSetLogic extends BaseGetXController { if (entity.errorCode!.codeIsSuccessful) { UdpHelp().closeUDP(); logOut(); - BlueManage().disconnect(BlueManage().connectDeviceMacAddress); + BlueManage().disconnect(); Get.offNamedUntil(Routers.starLockLoginPage, (route) => false); } } diff --git a/star_lock/lib/starLockApplication/starLockApplication.dart b/star_lock/lib/starLockApplication/starLockApplication.dart index fbf664a9..2c4dbd7f 100644 --- a/star_lock/lib/starLockApplication/starLockApplication.dart +++ b/star_lock/lib/starLockApplication/starLockApplication.dart @@ -3,6 +3,7 @@ import 'package:star_lock/login/login/starLock_login_page.dart'; import 'package:star_lock/tools/appFirstEnterHandle.dart'; import 'package:star_lock/tools/storage.dart'; +import '../blue/blue_manage.dart'; import '../main/lockMian/lockMain/lockMain_page.dart'; class StarLockApplication extends StatefulWidget { diff --git a/star_lock/pubspec.yaml b/star_lock/pubspec.yaml index 52156863..32c5fc88 100644 --- a/star_lock/pubspec.yaml +++ b/star_lock/pubspec.yaml @@ -76,7 +76,8 @@ dependencies: #跳转到外部 url_launcher: ^6.1.10 #蓝牙 - flutter_reactive_ble: ^5.1.1 +# flutter_reactive_ble: ^5.1.1 + flutter_blue_plus: ^1.31.16 # event_bus: ^2.0.0 #菊花