1、切换蓝牙插件。2、修复蓝牙概率连接失败问题。3、修复概率闪退问题。4、修复其他问题

This commit is contained in:
魏少阳 2024-03-18 16:16:51 +08:00
parent 38ab3c161b
commit b07ac6302b
48 changed files with 878 additions and 807 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -27,6 +27,8 @@ PODS:
- AMapFoundation (1.8.2)
- AMapLocation (2.10.0):
- AMapFoundation (>= 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

View File

@ -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<ScanResult>);
class BlueManage {
FlutterReactiveBle? _flutterReactiveBle;
final List<DiscoveredDevice> scanDevices = [];
final List<ScanResult> 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<EventSendModel>? _sendStreamSubscription;
//
StreamSubscription? _scanSubscription;
// StreamSubscription? _scanSubscription;
//
StreamSubscription<dynamic>? _currentConnectionStream;
// StreamSubscription<dynamic>? _currentConnectionStream;
// StreamSubscription<List<ScanResult>>? _scanResultsSubscription;
StreamSubscription<BluetoothConnectionState>? _connectionStateSubscription;
StreamSubscription<int>? _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<BluetoothAdapterState>? _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<EventSendModel>().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<Uuid>? idList}) {
// List<Service>? 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<void> startScan(int timeout, ScanDevicesCallBack scanDevicesCallBack, {List<Guid>? 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<void> 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<void> _connect(String deviceName, ConnectStateCallBack connectStateCallBack) async {
///
Future<void> _connect(String deviceName, ConnectStateCallBack connectStateCallBack, {bool isAddEquipment = false}) async {
connectDeviceName = deviceName;
List<ScanResult> devicesList = scanDevices;
if(isAddEquipment == false){
startScan(10, (List<ScanResult> scanDevices){
print("扫描到的设备:$scanDevices");
devicesList = scanDevices;
_connectDevice(devicesList, deviceName, connectStateCallBack, isAddEquipment: isAddEquipment);
});
}else{
_connectDevice(devicesList, deviceName, connectStateCallBack, isAddEquipment: isAddEquipment);
}
}
Future<void> _connectDevice( List<ScanResult> 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>[];
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 = <int>[];
}
}
}, 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 = <int>[];
// }
// } 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 = <int>[];
// }
// }
// });
// });
}
//
Future<void> writeCharacteristicWithResponse(List<int> 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<int> 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<int> 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<BluetoothService> services = await bluetoothConnectDevice!.discoverServices();
// BluetoothCharacteristic characteristic = services
// .firstWhere((service) => service.uuid == _serviceIdWrite)
// .characteristics
// .firstWhere((char) => char.uuid == _characteristicIdWrite);
// try {
// List<int> 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<List<int>> _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<List<int>> _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<void> writeCharacteristicWithoutResponse(
QualifiedCharacteristic characteristic, List<int> value) async {
try {
await _flutterReactiveBle!
.writeCharacteristicWithoutResponse(characteristic, value: value);
} on Exception catch (e, s) {
// ignore: avoid_print
print(s);
rethrow;
}
}
// Future<void> writeCharacteristicWithoutResponse(
// QualifiedCharacteristic characteristic, List<int> 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<void> stopScan() async {
try {
await FlutterBluePlus.stopScan();
} catch (e) {
Get.log("停止扫描失败");
}
}
//
Future<void> disconnect(String deviceMAC) async {
Future<void> 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();
}
}

View File

@ -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<void> 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<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -119,7 +119,6 @@ class _AddCardPageState extends State<AddCardPage> {
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<AddCardPage> {
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<AddCardPage> {
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<AddCardPage> {
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<AddCardPage> {
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<AddCardPage> {
thumbColor: CupertinoColors.white,
value: state.isAdministrator.value,
onChanged: (value) {
setState(() {
state.isAdministrator.value = value;
});
state.isAdministrator.value = value;
},
);
}

View File

@ -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<int> 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<void> 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<int> publicKeyDataList = changeStringListToIntList(publicKey!);

View File

@ -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<int> 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;

View File

@ -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<void> 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<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -234,8 +235,8 @@ class CardListLogic extends BaseGetXController {
// ()
Future<void> 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<int> 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<int> 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){

View File

@ -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<void> 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<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -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<int> 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();
}

View File

@ -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<int> 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;

View File

@ -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<void> 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<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -273,8 +274,8 @@ class FaceListLogic extends BaseGetXController {
// ()
Future<void> 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<int> 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<int> 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) {

View File

@ -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<int> 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<void> 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<int> publicKeyDataList = changeStringListToIntList(publicKey!);

View File

@ -119,7 +119,6 @@ class _AddFingerprintTypePageState extends State<AddFingerprintTypePage> {
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<AddFingerprintTypePage> {
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<AddFingerprintTypePage> {
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<AddFingerprintTypePage> {
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<AddFingerprintTypePage> {
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<AddFingerprintTypePage> {
thumbColor: CupertinoColors.white,
value: state.isAdministrator.value,
onChanged: (value) {
setState(() {
state.isAdministrator.value = value;
});
state.isAdministrator.value = value;
},
);
}

View File

@ -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<int> 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;

View File

@ -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<void> 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<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -267,8 +268,8 @@ class FingerprintListLogic extends BaseGetXController{
// ()
Future<void> 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<int> 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<int> 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){

View File

@ -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<int> 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<int> getTokenList = changeStringListToIntList(token!);
print("调用了开锁事件 openDoorTokenPubToken:$getTokenList getPrivateKeyList:$getPrivateKeyList");
// print("调用了开锁事件 openDoorTokenPubToken:$getTokenList getPrivateKeyList:$getPrivateKeyList");
// List<int>listData = 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<void> 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<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -850,9 +850,9 @@ class _LockDetailPageState extends State<LockDetailPage> 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<LockDetailPage> 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<LockDetailPage> 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<LockDetailPage> with TickerProviderStat
BlueManage().stopScan();
state.openLockBtnState.value = 0;
if (state.animationController!.isAnimating) {
state.animationController!.stop();
}
// if (state.animationController!.isAnimating) {
// state.animationController!.stop();
// }
}
}

View File

@ -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<void> 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<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -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<void> _readSupportFunctionsWithParameters() async {
// BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
//
// var token = await Storage.getStringList(saveBlueToken);
// List<int> getTokenList = changeStringListToIntList(token!);
//
// var publicKey = await Storage.getStringList(saveBluePublicKey);
// List<int> 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<void> 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<int> 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;

View File

@ -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<int> 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<int> 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();

View File

@ -9,34 +9,6 @@ import 'basicInformation_state.dart';
class BasicInformationLogic extends BaseGetXController{
final BasicInformationState state = BasicInformationState();
// -
// Future<void> _readAdminPassword() async {
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
//
// var token = await Storage.getStringList(saveBlueToken);
// List<int> getTokenList = changeStringListToIntList(token!);
//
// var publicKey = await Storage.getStringList(saveBluePublicKey);
// List<int> 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) {

View File

@ -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<int> 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;

View File

@ -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<void> _readSupportFunctionsNoParameters() async {
// BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
//
// var token = await Storage.getStringList(saveBlueToken);
// List<int> getTokenList = changeStringListToIntList(token!);
//
// var publicKey = await Storage.getStringList(saveBluePublicKey);
// List<int> 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<void> 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<int> 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() {

View File

@ -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<int> 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;

View File

@ -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<int> 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();

View File

@ -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<int> 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<int> 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<List<DiscoveredDevice>>_scanListDiscoveredDeviceSubscription;
void _scanListDiscoveredDeviceSubscriptionAction() {
_scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on<List<DiscoveredDevice>>().listen((List<DiscoveredDevice> 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<List<DiscoveredDevice>>_scanListDiscoveredDeviceSubscription;
// void _scanListDiscoveredDeviceSubscriptionAction() {
// _scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on<List<DiscoveredDevice>>().listen((List<DiscoveredDevice> 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<ScanResult> 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();
}
}

View File

@ -778,7 +778,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
!state.deletWaitScanCompleter!.isCompleted) {
state.deletWaitScanCompleter!.complete();
}
BlueManage().stopScan();
// BlueManage().stopScan();
state.ifCurrentScreen.value = false;
}
@ -805,7 +805,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
!state.deletWaitScanCompleter!.isCompleted) {
state.deletWaitScanCompleter!.complete();
}
BlueManage().stopScan();
// BlueManage().stopScan();
state.ifCurrentScreen.value = false;
}
}

View File

@ -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;//

View File

@ -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<void> _readSupportFunctionsWithParameters() async {
// BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
//
// var token = await Storage.getStringList(saveBlueToken);
// List<int> getTokenList = changeStringListToIntList(token!);
//
// var publicKey = await Storage.getStringList(saveBluePublicKey);
// List<int> 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<void> 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<int> 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;

View File

@ -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<void> _getLockStatus() async {
// //
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
// if (state == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
// IoSenderManage.senderGetLockStatu(
// lockID:BlueManage().connectDeviceName,
// userID:await Storage.getUid(),
// privateKey:getPrivateKeyList,
// );
// }
// }, isShowLoading: false);
// }
//
Future<void> 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<int> 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;

View File

@ -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<void> _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<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -135,8 +137,8 @@ class MotorPowerLogic extends BaseGetXController {
// ()
Future<void> 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<int> getPrivateKeyList = changeStringListToIntList(privateKey!);

View File

@ -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<void> _readSupportFunctionsWithParameters() async {
// BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
//
// var token = await Storage.getStringList(saveBlueToken);
// List<int> getTokenList = changeStringListToIntList(token!);
//
// var publicKey = await Storage.getStringList(saveBluePublicKey);
// List<int> 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<void> 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<int> 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;

View File

@ -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<void> _readSupportFunctionsNoParameters() async {
// BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
//
// var token = await Storage.getStringList(saveBlueToken);
// List<int> getTokenList = changeStringListToIntList(token!);
//
// var publicKey = await Storage.getStringList(saveBluePublicKey);
// List<int> 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<void> 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<int> 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();
}

View File

@ -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<void> _readSupportFunctionsNoParameters() async {
// BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
//
// var token = await Storage.getStringList(saveBlueToken);
// List<int> getTokenList = changeStringListToIntList(token!);
//
// var publicKey = await Storage.getStringList(saveBluePublicKey);
// List<int> 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<void> 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<int> 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;

View File

@ -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<void> _readSupportFunctionsNoParameters() async {
// BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
// if (connectionState == DeviceConnectionState.connected) {
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
//
// var token = await Storage.getStringList(saveBlueToken);
// List<int> getTokenList = changeStringListToIntList(token!);
//
// var publicKey = await Storage.getStringList(saveBluePublicKey);
// List<int> 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<void> 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<int> 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;

View File

@ -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<int> 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;

View File

@ -76,6 +76,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> wit
return Column(
children: [
perpetualKeyWidget(
false,
TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
state.nameController),
@ -90,6 +91,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> wit
children: [
keyTimeLimitWidget(),
perpetualKeyWidget(
false,
TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
state.nameController),
@ -103,6 +105,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> wit
return Column(
children: [
perpetualKeyWidget(
false,
TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
state.nameController),
@ -120,11 +123,16 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> 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<PasswordKeyPerpetualPage> wit
children: [
keyCirculationWidget(),
perpetualKeyWidget(
true,
TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
state.nameController),
@ -149,6 +158,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> wit
return Column(
children: [
perpetualKeyWidget(
false,
TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
state.nameController),
@ -164,10 +174,10 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> 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<PasswordKeyPerpetualPage> 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<PasswordKeyPerpetualPage> 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<PasswordKeyPerpetualPage> 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";
}

View File

@ -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;

View File

@ -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

View File

@ -386,7 +386,7 @@ class _LockAddressGaoDePageState extends State<LockAddressGaoDePage> with RouteA
AppRouteObserver().routeObserver.unsubscribe(this);
super.dispose();
BlueManage().disconnect(BlueManage().connectDeviceMacAddress);
BlueManage().disconnect();
location.stopLocation();
location.destroy();

View File

@ -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<void> _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<int> 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<List<DiscoveredDevice>>_scanListDiscoveredDeviceSubscription;
void _scanListDiscoveredDeviceSubscriptionAction() {
_scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on<List<DiscoveredDevice>>().listen((List<DiscoveredDevice> list) {
// late StreamSubscription<List<ScanResult>>_scanListDiscoveredDeviceSubscription;
// void _scanListDiscoveredDeviceSubscriptionAction() {
// _scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on<List<ScanResult>>().listen((List<ScanResult> 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<ScanResult> 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();
}
}

View File

@ -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<NearbyLockPage> 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<NearbyLockPage> 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<NearbyLockPage> with RouteAware {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 323300 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<NearbyLockPage> with RouteAware {
state.ifCurrentScreen.value = false;
logic.cancelBlueConnetctToastTimer();
logic.stopScanBlueList();
BlueManage().disconnect();
}
///
@ -184,6 +187,7 @@ class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
state.ifCurrentScreen.value = false;
logic.cancelBlueConnetctToastTimer();
logic.stopScanBlueList();
BlueManage().disconnect();
}
}

View File

@ -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<DiscoveredDevice> devices = <DiscoveredDevice>[].obs;
RxList<ScanResult> devices = <ScanResult>[].obs;
var ifCurrentScreen = true.obs; // ,
var selectLockName = "".obs;

View File

@ -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<int> 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<int> 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);
}

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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
#菊花