优化蓝牙功能
This commit is contained in:
parent
b3ee82d605
commit
16d5d53c61
@ -45,7 +45,7 @@ PODS:
|
||||
- FMDB/standard (2.7.5)
|
||||
- google_maps_flutter_ios (0.0.1):
|
||||
- Flutter
|
||||
- GoogleMaps (< 8.0)
|
||||
- GoogleMaps (< 9.0)
|
||||
- GoogleMaps (5.2.0):
|
||||
- GoogleMaps/Maps (= 5.2.0)
|
||||
- GoogleMaps/Base (5.2.0)
|
||||
@ -192,7 +192,7 @@ SPEC CHECKSUMS:
|
||||
flutter_native_contact_picker: bd430ba0fbf82768bb50c2c52a69a65759a8f907
|
||||
fluttertoast: 31b00dabfa7fb7bacd9e7dbee580d7a2ff4bf265
|
||||
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
|
||||
google_maps_flutter_ios: abdac20d6ce8931f6ebc5f46616df241bfaa2cfd
|
||||
google_maps_flutter_ios: 590249c67f34f422122c232f2a626192adbc78ee
|
||||
GoogleMaps: 025272d5876d3b32604e5c080dc25eaf68764693
|
||||
image_picker_ios: 4a8aadfbb6dc30ad5141a2ce3832af9214a705b5
|
||||
network_info_plus: 6d0c3eb8367b8164fa3fb0c19875e3f59d49697f
|
||||
@ -205,7 +205,7 @@ SPEC CHECKSUMS:
|
||||
sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a
|
||||
SwiftProtobuf: 69f02cd54fb03201c5e6bf8b76f687c5ef7541a3
|
||||
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
|
||||
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4
|
||||
url_launcher_ios: bf5ce03e0e2088bad9cc378ea97fa0ed5b49673b
|
||||
video_player_avfoundation: 81e49bb3d9fb63dccf9fa0f6d877dc3ddbeac126
|
||||
webview_flutter_wkwebview: 2e2d318f21a5e036e2c3f26171342e95908bd60a
|
||||
|
||||
|
||||
@ -3,37 +3,39 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/blue/sender_manage.dart';
|
||||
|
||||
import '../tools/toast.dart';
|
||||
import '../translations/trans_lib.dart';
|
||||
import 'io_tool/io_model.dart';
|
||||
import 'io_tool/io_tool.dart';
|
||||
import 'io_tool/manager_event_bus.dart';
|
||||
import 'reciver_data.dart';
|
||||
|
||||
typedef ScanResultCallBack = void Function(List<DiscoveredDevice> devices);
|
||||
//连接状态回调
|
||||
typedef ConnectStateCallBack = Function(DeviceConnectionState connectionState);
|
||||
|
||||
class BlueManage{
|
||||
FlutterReactiveBle? _flutterReactiveBle;
|
||||
final List<DiscoveredDevice> _scanDevices = [];
|
||||
final List<DiscoveredDevice> scanDevices = [];
|
||||
|
||||
// 用来写入的服务id
|
||||
Uuid serviceId = Uuid.parse('0000FFF0-0000-1000-8000-00805F9B34FB');
|
||||
Uuid characteristicIdSubscription = Uuid.parse("fff1");//用来订阅的特征id
|
||||
Uuid characteristicIdWrite = Uuid.parse("fff2");// 用来写入的特征id
|
||||
String connectDeviceMacAddress = "";
|
||||
String connectDeviceName = "";
|
||||
// 用来订阅的特征id
|
||||
Uuid characteristicIdSubscription = Uuid.parse("fff1");
|
||||
// 用来写入的特征id
|
||||
Uuid characteristicIdWrite = Uuid.parse("fff2");
|
||||
|
||||
// final int _limitLen = 20;
|
||||
|
||||
// 监听发送事件
|
||||
// 发送监听发送事件
|
||||
StreamSubscription<EventSendModel>? _sendStreamSubscription;
|
||||
// 监听蓝牙扫描的事件
|
||||
StreamSubscription? _scanSubscription;
|
||||
// 监听蓝牙连接的事件
|
||||
StreamSubscription<dynamic>? _currentConnectionStream;
|
||||
|
||||
// 当前连接设备的名字
|
||||
String connectDeviceName = "";
|
||||
// 当前连接设备的mac地址
|
||||
String connectDeviceMacAddress = "";
|
||||
// 监听蓝牙连接状态
|
||||
DeviceConnectionState? deviceConnectionState = DeviceConnectionState.disconnected;
|
||||
|
||||
@ -50,7 +52,7 @@ class BlueManage{
|
||||
BlueManage? get manager => shareManager();
|
||||
|
||||
void _initBlue(){
|
||||
_flutterReactiveBle = FlutterReactiveBle();
|
||||
_flutterReactiveBle ??= FlutterReactiveBle();
|
||||
print("蓝牙功能初始化了");
|
||||
_initSendStreamSubscription();
|
||||
}
|
||||
@ -66,240 +68,126 @@ class BlueManage{
|
||||
}
|
||||
|
||||
/// 开始扫描蓝牙设备
|
||||
void startScan(bool isScanAll, ScanResultCallBack scanResultCallBack) {
|
||||
_scanDevices.clear();
|
||||
_scanSubscription = _flutterReactiveBle!.scanForDevices(withServices: []).listen((device) {
|
||||
void startScan({List<Uuid>? idList}) {
|
||||
scanDevices.clear();
|
||||
_scanSubscription = _flutterReactiveBle!.scanForDevices(withServices: idList??[]).listen((device) {
|
||||
// 判断名字为空的直接剔除
|
||||
if(device.name.isEmpty){
|
||||
return;
|
||||
}
|
||||
// print("startScanDevice:${device}");
|
||||
// 判断是否
|
||||
if(isScanAll == true){
|
||||
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);
|
||||
}
|
||||
|
||||
scanResultCallBack(_scanDevices);
|
||||
}
|
||||
}else{
|
||||
if (((device.serviceUuids.isNotEmpty ? device.serviceUuids[0] : "").toString().contains("758824")) && ((device.serviceUuids.isNotEmpty ? device.serviceUuids[0] : "").toString()[31] != "1") && (device.rssi >= -100)) {
|
||||
// 查询id相同的元素
|
||||
final knownDeviceIndex = _scanDevices.indexWhere((d) => d.id == device.id);
|
||||
// 不存在的时候返回-1
|
||||
if (knownDeviceIndex >= 0) {
|
||||
_scanDevices[knownDeviceIndex] = device;
|
||||
} else {
|
||||
_scanDevices.add(device);
|
||||
}
|
||||
// print("_scanDevices:$_scanDevices");
|
||||
scanResultCallBack(_scanDevices);
|
||||
// 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);
|
||||
}
|
||||
EventBusManager().eventBusFir(scanDevices);
|
||||
}
|
||||
|
||||
}, onError: (Object e) {
|
||||
print('Device scan fails with error: $e');
|
||||
});
|
||||
}
|
||||
|
||||
/// 连接监听状态
|
||||
Future<void> connect(String deviceMAC, String deviceName, {ConnectStateCallBack? connectStateCallBack, bool? isFrist = false ,bool isShowLoading = true}) async {
|
||||
connectDeviceMacAddress = deviceMAC;
|
||||
Future<void> connect(String deviceName, ConnectStateCallBack connectStateCallBack, {bool? isFrist = false ,bool isShowLoading = true}) async {
|
||||
connectDeviceName = deviceName;
|
||||
print("connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName");
|
||||
// 判断数组列表里面是否有这个设备
|
||||
final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName);
|
||||
|
||||
if(isShowLoading){
|
||||
EasyLoading.show();
|
||||
Future.delayed(const Duration(seconds: 10), () { //asynchronous delay
|
||||
print("10s之后 菊花没有隐藏的话,强制隐藏菊花");
|
||||
if(EasyLoading.isShow){
|
||||
EasyLoading.dismiss();
|
||||
if (knownDeviceIndex >= 0) {
|
||||
// 存在的时候赋值
|
||||
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
|
||||
} else {
|
||||
// 不存在的时候返回-1 然后循环5秒
|
||||
var index = 0;
|
||||
Completer? completer = Completer();
|
||||
Timer.periodic(const Duration(milliseconds: 1000), (timer) {
|
||||
///定时任务
|
||||
print("timer index:$index");
|
||||
if(index >= 4){
|
||||
// 当超过5秒的时候取消定时任务 弹窗显示连接失败
|
||||
completer.complete();
|
||||
timer.cancel();
|
||||
connectDeviceMacAddress = "";
|
||||
deviceConnectionState = DeviceConnectionState.disconnected;
|
||||
connectStateCallBack(deviceConnectionState!);
|
||||
Toast.show(msg: "未扫描到要连接的设备,请确保在设备附近,设备未被连接,设备已打开");
|
||||
}else{
|
||||
// 每秒判断数组列表里面是否有这个设备
|
||||
final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName);
|
||||
if (knownDeviceIndex >= 0) {
|
||||
// 存在的时候销毁定时器,赋值
|
||||
completer.complete();
|
||||
timer.cancel();
|
||||
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
|
||||
} else {
|
||||
// 不存在的时候返回-1 然后循环5秒
|
||||
index++;
|
||||
print("index:$index 没有找到设备");
|
||||
}
|
||||
}
|
||||
});
|
||||
// 等待Completer完成
|
||||
await completer.future;
|
||||
// print("111111");
|
||||
}
|
||||
print("connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName");
|
||||
|
||||
if(deviceConnectionState == DeviceConnectionState.connected){
|
||||
if(connectDeviceMacAddress.isEmpty){
|
||||
return;
|
||||
}
|
||||
_currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(seconds: 100000)).listen((connectionStateUpdate) async {
|
||||
|
||||
_currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(milliseconds: 10000)).listen((connectionStateUpdate) async {
|
||||
// 获取状态
|
||||
deviceConnectionState = connectionStateUpdate.connectionState;
|
||||
print('ConnectionState for device $deviceMAC : ${connectionStateUpdate.connectionState}');
|
||||
|
||||
// if(connectionStateUpdate.connectionState != DeviceConnectionState.connected){
|
||||
// EasyLoading.dismiss();
|
||||
// }
|
||||
|
||||
print('deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}');
|
||||
if(connectionStateUpdate.connectionState == DeviceConnectionState.connected){
|
||||
// 如果状态是连接的开始发现服务
|
||||
// await discoverServices(connectDeviceId, connectDeviceName);
|
||||
try {
|
||||
// print('Start discovering services for: $deviceId');
|
||||
List<DiscoveredService> result = await _flutterReactiveBle!.discoverServices(deviceMAC);
|
||||
// print("mmmmmmmmm$result");
|
||||
if(result.isNotEmpty){
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
DiscoveredService discoveredService = result[i];
|
||||
if (discoveredService.serviceId.toString() == "fff0"){
|
||||
// getDiscoveredService = discoveredService;
|
||||
for (var j = 0; j < discoveredService.characteristics.length; j++) {
|
||||
DiscoveredCharacteristic discoveredCharacteristic = discoveredService.characteristics[j];
|
||||
if (discoveredCharacteristic.characteristicId.toString() == "fff1") {
|
||||
// 订阅用
|
||||
characteristicIdSubscription = discoveredCharacteristic.characteristicId;
|
||||
// print("Subscription characteristicId:${result[i].characteristicIds[j].toString()} serviceId:${result[i].serviceId} deviceId:$deviceMAC");
|
||||
}
|
||||
if (discoveredCharacteristic.characteristicId.toString() == "fff2") {
|
||||
// 用来写入
|
||||
characteristicIdWrite= discoveredCharacteristic.characteristicId;
|
||||
// print("1111111111111111characteristicId:${discoveredCharacteristic.characteristicId} serviceId:${serviceId} deviceId:$deviceId");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
EasyLoading.dismiss();
|
||||
}
|
||||
_subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: characteristicIdSubscription, serviceId: Uuid.parse("fff0"), deviceId: deviceMAC));
|
||||
_subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: characteristicIdSubscription, serviceId: Uuid.parse("fff0"), deviceId: connectDeviceMacAddress));
|
||||
print('Discovering services finished');
|
||||
|
||||
if(isFrist == true){
|
||||
// var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
// List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
// if(publicKeyDataList.isNotEmpty ){
|
||||
// IoSenderManage.getPrivateKey(
|
||||
// lockId:BlueManage().connectDeviceName,
|
||||
// keyID:"1",
|
||||
// authUserID:"1",
|
||||
// nowTime:1,
|
||||
// publicKeyData:publicKeyDataList,
|
||||
// needAuthor:1);
|
||||
// }else{
|
||||
// 第一次添加锁的时候需要先获取公钥
|
||||
IoSenderManage.getPublicKey(lockId: deviceName);
|
||||
// }
|
||||
// 第一次添加锁的时候需要先获取公钥
|
||||
IoSenderManage.getPublicKey(lockId: deviceName);
|
||||
}
|
||||
connectStateCallBack!(connectionStateUpdate.connectionState);
|
||||
// print("333333:$deviceConnectionState");
|
||||
deviceConnectionState = connectionStateUpdate.connectionState;
|
||||
connectStateCallBack(deviceConnectionState!);
|
||||
} on Exception catch (e) {
|
||||
EasyLoading.dismiss();
|
||||
deviceConnectionState = DeviceConnectionState.disconnected;
|
||||
connectStateCallBack(deviceConnectionState!);
|
||||
print('Error occurred when discovering services: $e');
|
||||
rethrow;
|
||||
}
|
||||
} else{
|
||||
deviceConnectionState = connectionStateUpdate.connectionState;
|
||||
connectStateCallBack(deviceConnectionState!);
|
||||
}
|
||||
print('ConnectionState for device $connectDeviceMacAddress : ${connectionStateUpdate.connectionState}');
|
||||
}, onError: (Object e){
|
||||
EasyLoading.dismiss();
|
||||
print('Connecting to device $deviceMAC resulted in error $e');
|
||||
}
|
||||
deviceConnectionState = DeviceConnectionState.disconnected;
|
||||
connectStateCallBack(deviceConnectionState!);
|
||||
print('Connecting to device $connectDeviceMacAddress resulted in error $e');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// 停止扫描蓝牙设备
|
||||
Future<void> stopScan() async {
|
||||
await _scanSubscription?.cancel();
|
||||
_scanSubscription = null;
|
||||
}
|
||||
|
||||
// 断开连接
|
||||
Future<void> disconnect(String deviceMAC) async {
|
||||
|
||||
try {
|
||||
_currentConnectionStream?.cancel();
|
||||
print('disconnecting to device: $deviceMAC');
|
||||
} on Exception catch (e, _) {
|
||||
print("Error disconnecting from a device: $e");
|
||||
} finally {
|
||||
deviceConnectionState = DeviceConnectionState.disconnected;
|
||||
// _currentConnectionStream = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 重新连接
|
||||
Future<void> judgeReconnect(String deviceMAC, String deviceName, ConnectStateCallBack? connectStateCallBack, {bool isShowLoading = true, bool isShowToast = true}) async {
|
||||
// print("11111111$deviceConnectionState");
|
||||
if(isShowToast){
|
||||
if(deviceMAC.isEmpty){
|
||||
Toast.show(msg: TranslationLoader.lanKeys!.connectBlueErrorTip!.tr);
|
||||
// return;
|
||||
}
|
||||
}
|
||||
|
||||
if(deviceConnectionState == DeviceConnectionState.connected){
|
||||
// print("2222222:$deviceConnectionState");
|
||||
if(isShowLoading){
|
||||
EasyLoading.show();
|
||||
Future.delayed(const Duration(seconds: 10), () { //asynchronous delay
|
||||
print("10s之后 菊花没有隐藏的话,强制隐藏菊花");
|
||||
if(EasyLoading.isShow){
|
||||
EasyLoading.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
connectStateCallBack!(deviceConnectionState!);
|
||||
Future<void> judgeReconnect(String deviceName, ConnectStateCallBack stateCallBack, {bool isShowLoading = true}) async {
|
||||
if(deviceConnectionState != DeviceConnectionState.connected){
|
||||
connect(deviceName, (state){
|
||||
stateCallBack(deviceConnectionState!);
|
||||
}, isShowLoading: false);
|
||||
}else{
|
||||
// print("333333333:${deviceConnectionState}");
|
||||
connect(deviceMAC, deviceName, isShowLoading: false, connectStateCallBack: (state){
|
||||
// print("44444444:${state}");
|
||||
// if(deviceConnectionState == DeviceConnectionState.connected){
|
||||
connectStateCallBack!(state);
|
||||
// }else {
|
||||
// Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
|
||||
// }
|
||||
});
|
||||
stateCallBack(deviceConnectionState!);
|
||||
}
|
||||
}
|
||||
|
||||
// 扫描服务,并过滤服务
|
||||
// Future<List<DiscoveredService>> discoverServices(String deviceMAC, String deviceName, {bool? isFrist = false}) async {
|
||||
// try {
|
||||
// // print('Start discovering services for: $deviceId');
|
||||
// List<DiscoveredService> result = await _flutterReactiveBle!.discoverServices(deviceMAC);
|
||||
// // print("mmmmmmmmm$result");
|
||||
// if(result.isNotEmpty){
|
||||
// for (var i = 0; i < result.length; i++) {
|
||||
// DiscoveredService discoveredService = result[i];
|
||||
// // print("objectdiscoveredService.serviceId.toString() ${discoveredService.serviceId.toString()}");
|
||||
// if (discoveredService.serviceId.toString() == "fff0"){
|
||||
// // getDiscoveredService = discoveredService;
|
||||
// for (var j = 0; j < discoveredService.characteristics.length; j++) {
|
||||
// DiscoveredCharacteristic discoveredCharacteristic = discoveredService.characteristics[j];
|
||||
//
|
||||
// // print("hhhhhhhhhh${result[i].characteristicIds[j].toString()}");
|
||||
// if (discoveredCharacteristic.characteristicId.toString() == "fff1") {
|
||||
// // 订阅用
|
||||
// characteristicIdSubscription = discoveredCharacteristic.characteristicId;
|
||||
// // getDiscoveredCharacteristic = discoveredCharacteristic;
|
||||
// print("1111111111111111characteristicId:${result[i].characteristicIds[j].toString()} serviceId:${result[i].serviceId} deviceId:$deviceMAC");
|
||||
// }
|
||||
// if (discoveredCharacteristic.characteristicId.toString() == "fff2") {
|
||||
// // 用来写入
|
||||
// characteristicIdWrite= discoveredCharacteristic.characteristicId;
|
||||
// // print("1111111111111111characteristicId:${discoveredCharacteristic.characteristicId} serviceId:${serviceId} deviceId:$deviceId");
|
||||
// // qualifiedCharacteristic = QualifiedCharacteristic(characteristicId: discoveredCharacteristic.characteristicId, serviceId:serviceId , deviceId: deviceId);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// _subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: characteristicIdSubscription, serviceId: Uuid.parse("fff0"), deviceId: deviceMAC));
|
||||
// print('Discovering services finished');
|
||||
//
|
||||
// if(isFrist == true){
|
||||
// // 第一次添加锁的时候需要先获取公钥
|
||||
// IoSenderManage.getPublicKey(lockId: deviceName);
|
||||
// }
|
||||
// return result;
|
||||
// } on Exception catch (e) {
|
||||
// print('Error occurred when discovering services: $e');
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
|
||||
// 听上报来的数据,参数来自前面扫描到的结果
|
||||
var allData = <int>[];
|
||||
_subScribeToCharacteristic(QualifiedCharacteristic characteristic) {
|
||||
@ -344,7 +232,7 @@ class BlueManage{
|
||||
// 写入
|
||||
Future<void> writeCharacteristicWithResponse(List<int> value) async {
|
||||
QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: characteristicIdWrite, serviceId: serviceId, deviceId: connectDeviceMacAddress);
|
||||
print('Write with characteristicId:${characteristic.characteristicId} serviceId:${characteristic.serviceId} deviceId:${characteristic.deviceId} value : $value \nhexStr:${radixHex16String(value)}');
|
||||
// print('Write with characteristicId:${characteristic.characteristicId} serviceId:${characteristic.serviceId} deviceId:${characteristic.deviceId} value : $value \nhexStr:${radixHex16String(value)}');
|
||||
int mtuLength = await _flutterReactiveBle!.requestMtu(deviceId: characteristic.deviceId, mtu: 250);
|
||||
print("mtuLength:$mtuLength");
|
||||
try {
|
||||
@ -392,8 +280,28 @@ class BlueManage{
|
||||
}
|
||||
}
|
||||
|
||||
// 停止扫描蓝牙设备
|
||||
Future<void> stopScan() async {
|
||||
await _scanSubscription?.cancel();
|
||||
_scanSubscription = null;
|
||||
}
|
||||
|
||||
// 断开连接
|
||||
Future<void> disconnect(String deviceMAC) async {
|
||||
try {
|
||||
_currentConnectionStream?.cancel();
|
||||
print('disconnecting to device: $deviceMAC');
|
||||
} on Exception catch (e, _) {
|
||||
print("Error disconnecting from a device: $e");
|
||||
} finally {
|
||||
deviceConnectionState = DeviceConnectionState.disconnected;
|
||||
// _currentConnectionStream = null;
|
||||
}
|
||||
}
|
||||
|
||||
disposed(){
|
||||
_sendStreamSubscription?.cancel();
|
||||
_currentConnectionStream?.cancel();
|
||||
_scanSubscription?.cancel();
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:star_lock/tools/app_manager.dart';
|
||||
import 'package:star_lock/tools/bindings/app_binding.dart';
|
||||
import 'package:star_lock/tools/device_info_service.dart';
|
||||
@ -17,6 +18,7 @@ import 'package:star_lock/translations/trans_lib.dart';
|
||||
|
||||
import 'appRouters.dart';
|
||||
import 'baseWidget.dart';
|
||||
import 'blue/blue_manage.dart';
|
||||
import 'tools/appRouteObserver.dart';
|
||||
import 'tools/store_service.dart';
|
||||
import 'dart:io';
|
||||
@ -79,8 +81,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
|
||||
}
|
||||
}
|
||||
// print("localelocalelocalelocalelocale locale:${locale} locale.languageCode:${locale.languageCode} locale.countryCode:${locale.countryCode} supportedLocales:${supportedLocales}");
|
||||
AppManager()
|
||||
.setLanCode(code: '${locale!.languageCode}_${locale.countryCode}');
|
||||
AppManager().setLanCode(code: '${locale!.languageCode}_${locale.countryCode}');
|
||||
return locale;
|
||||
},
|
||||
// locale: StoreService.to.getLanguageCode().isNotEmpty ? appDept.deptSupportedLocales.where((element) => element.languageCode == StoreService.to.getLanguageCode()).first : Get.deviceLocale,
|
||||
@ -123,6 +124,8 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
|
||||
super.initState();
|
||||
WidgetsBinding.instance?.addObserver(this);
|
||||
|
||||
openBlueScan();
|
||||
|
||||
initAliyunPush();
|
||||
}
|
||||
|
||||
@ -184,6 +187,46 @@ Future _setCommonServices() async {
|
||||
// Get.log(PlatformInfoService.to.info.version);
|
||||
}
|
||||
|
||||
void openBlueScan(){
|
||||
if(Platform.isIOS){
|
||||
print("有蓝牙权限开始扫描");
|
||||
startScanAction();
|
||||
}else{
|
||||
getMicrophonePermission().then((value) {
|
||||
if (value) {
|
||||
// 有权限
|
||||
print("有蓝牙权限开始扫描");
|
||||
startScanAction();
|
||||
}else{
|
||||
//没有权限
|
||||
openAppSettings();//打开app系统设置
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void startScanAction(){
|
||||
BlueManage().startScan();
|
||||
}
|
||||
|
||||
///请求蓝牙权限
|
||||
Future<bool> getMicrophonePermission() async {
|
||||
// You can request multiple permissions at once.
|
||||
Map<Permission, PermissionStatus> statuses = await [
|
||||
Permission.bluetoothScan,
|
||||
Permission.bluetoothConnect,
|
||||
Permission.location,
|
||||
].request();
|
||||
|
||||
//granted 通过,denied 被拒绝,permanentlyDenied 拒绝且不在提示
|
||||
if (statuses[Permission.bluetoothScan]!.isGranted &&
|
||||
statuses[Permission.bluetoothConnect]!.isGranted &&
|
||||
statuses[Permission.location]!.isGranted) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//播放本地音频
|
||||
// void playAudio() async {
|
||||
// const String audioPath = "assets/ring1.mp3";
|
||||
|
||||
@ -163,9 +163,7 @@ class AuthorizedAdminLogic extends BaseGetXController {
|
||||
|
||||
// 转移权限
|
||||
Future<void> transferPermissionsAction() async {
|
||||
BlueManage().judgeReconnect(
|
||||
BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName,
|
||||
(DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -194,9 +192,7 @@ class AuthorizedAdminLogic extends BaseGetXController {
|
||||
// 添加用户
|
||||
Future<void> addUserConnectBlue(String receiveId) async {
|
||||
// 进来之后首先连接
|
||||
BlueManage().judgeReconnect(
|
||||
BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName,
|
||||
(DeviceConnectionState connecteState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connecteState) async {
|
||||
if (connecteState == DeviceConnectionState.connected) {
|
||||
// 私钥
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
|
||||
@ -19,10 +19,9 @@ class _AddCardTypeManagePageState extends State<AddCardTypeManagePage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 0卡 1指纹 2钥匙
|
||||
Map map = Get.arguments;
|
||||
var lockId = map["lockId"];
|
||||
var fromType = map["fromType"]; // 1从添加钥匙列表进入 2从考勤添加员工入口进入
|
||||
var fromType = map["fromType"]??1; // 1从添加钥匙列表进入 2从考勤添加员工入口进入
|
||||
var fromTypeTwoStaffName = "";
|
||||
if(fromType == 2){
|
||||
fromTypeTwoStaffName = map["fromTypeTwoStaffName"]; // 从添加员工进入 传入员工名字
|
||||
|
||||
@ -40,6 +40,11 @@ class _AddCardManageTabbarState extends State<AddCardManageTabbar> with SingleTi
|
||||
vsync: this,
|
||||
length: _itemTabs.length,
|
||||
initialIndex: widget.initialIndex);
|
||||
_tabController.addListener(() {
|
||||
if (_tabController.animation!.value==_tabController.index){
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@ -56,6 +61,9 @@ class _AddCardManageTabbarState extends State<AddCardManageTabbar> with SingleTi
|
||||
TabBar _tabBar() {
|
||||
return TabBar(
|
||||
controller: _tabController,
|
||||
onTap: (index){
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
},
|
||||
tabs: _itemTabs.map((ItemView item) => _tab(item)).toList(),
|
||||
isScrollable: true,
|
||||
indicatorColor: Colors.red,
|
||||
@ -94,8 +102,7 @@ class _AddCardManageTabbarState extends State<AddCardManageTabbar> with SingleTi
|
||||
lockId: widget.lockId,
|
||||
fromType: widget.fromType,
|
||||
fromTypeTwoStaffName:widget.fromTypeTwoStaffName
|
||||
))
|
||||
.toList(),
|
||||
)).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -89,6 +89,8 @@ class AddCardTypeLogic extends BaseGetXController{
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_pickers/pickers.dart';
|
||||
// import 'package:flutter_pickers/time_picker/model/date_mode.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/tools/pickers/pickers.dart';
|
||||
|
||||
@ -214,7 +214,7 @@ class AddICCardLogic extends BaseGetXController{
|
||||
|
||||
// 添加卡片
|
||||
Future<void> senderAddICCard() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
@ -246,7 +246,7 @@ class AddICCardLogic extends BaseGetXController{
|
||||
|
||||
// 添加胁迫卡片
|
||||
Future<void> senderAddStressICCard() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
@ -88,7 +88,7 @@ class CardDetailLogic extends BaseGetXController{
|
||||
|
||||
// 删除卡片
|
||||
Future<void> senderAddICCard() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
@ -205,7 +205,7 @@ class CardListLogic extends BaseGetXController {
|
||||
|
||||
// 查询卡片状态
|
||||
Future<void> senderCheckingCardStatus() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -233,7 +233,7 @@ class CardListLogic extends BaseGetXController {
|
||||
|
||||
// 查询用户、指纹、密码、卡片数量(用于判断是否同步)
|
||||
Future<void> senderCheckingUserInfoCount() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -260,7 +260,7 @@ class CardListLogic extends BaseGetXController {
|
||||
|
||||
// 删除卡片
|
||||
Future<void> senderAddICCard() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
@ -144,10 +144,15 @@ class _CardListPageState extends State<CardListPage> {
|
||||
child: _keyItem(
|
||||
'images/icon_card.png',
|
||||
fingerprintItemData.cardName!,
|
||||
fingerprintItemData.cardType! == 1
|
||||
? "永久"
|
||||
:
|
||||
"${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())}", () async {
|
||||
fingerprintItemData.endDate! < DateTime.now().millisecondsSinceEpoch
|
||||
? "已失效"
|
||||
: "",
|
||||
fingerprintItemData.validTimeStr!,
|
||||
// fingerprintItemData.cardType! == 1
|
||||
// ? "永久"
|
||||
// :
|
||||
// "${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())}",
|
||||
() async {
|
||||
var data = await Get.toNamed(
|
||||
Routers.cardDetailPage, arguments: {
|
||||
"fingerprintItemData": fingerprintItemData,
|
||||
@ -216,7 +221,7 @@ class _CardListPageState extends State<CardListPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _keyItem(String lockTypeIcon, String lockTypeTitle, String showTime,
|
||||
Widget _keyItem(String lockTypeIcon, String lockTypeTitle, String ifInvalidation, String showTime,
|
||||
Function() action) {
|
||||
return GestureDetector(
|
||||
onTap: action,
|
||||
@ -238,11 +243,16 @@ class _CardListPageState extends State<CardListPage> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(lockTypeTitle,
|
||||
style: TextStyle(
|
||||
fontSize: 24.sp, color: AppColors.blackColor)),
|
||||
Expanded(child: Container()),
|
||||
Text(ifInvalidation,
|
||||
style: TextStyle(
|
||||
fontSize: 22.sp, color: Colors.red)),
|
||||
SizedBox(width: 10.w),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 5.h),
|
||||
|
||||
@ -252,7 +252,8 @@ class AddFingerprintLogic extends BaseGetXController {
|
||||
|
||||
// 添加指纹开始
|
||||
Future<void> senderAddFingerprint() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
// print("66666666:$deviceConnectionState");
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
@ -278,13 +279,16 @@ class AddFingerprintLogic extends BaseGetXController {
|
||||
privateKey:getPrivateKeyList,
|
||||
token: getTokenList,
|
||||
);
|
||||
}else if (deviceConnectionState == DeviceConnectionState.disconnected){
|
||||
// Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
|
||||
Get.close(2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 添加胁迫指纹
|
||||
Future<void> senderAddStressFingerprint() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
@ -39,6 +39,11 @@ class _AddFingerprintTypeManageTabbarState extends State<AddFingerprintTypeManag
|
||||
vsync: this,
|
||||
length: _itemTabs.length,
|
||||
initialIndex: widget.initialIndex);
|
||||
_tabController.addListener(() {
|
||||
if (_tabController.animation!.value==_tabController.index){
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@ -55,6 +60,9 @@ class _AddFingerprintTypeManageTabbarState extends State<AddFingerprintTypeManag
|
||||
TabBar _tabBar() {
|
||||
return TabBar(
|
||||
controller: _tabController,
|
||||
onTap: (index){
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
},
|
||||
tabs: _itemTabs.map((ItemView item) => _tab(item)).toList(),
|
||||
isScrollable: true,
|
||||
indicatorColor: Colors.red,
|
||||
|
||||
@ -89,7 +89,7 @@ class FingerprintDetailLogic extends BaseGetXController{
|
||||
|
||||
// 删除指纹
|
||||
Future<void> senderAddFingerprint() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
@ -76,6 +76,7 @@ class FingerprintItemData {
|
||||
int? fingerprintId;
|
||||
String? senderUsername;
|
||||
List? weekDay;
|
||||
String? validTimeStr;
|
||||
|
||||
String? cardName;
|
||||
String? cardNumber;
|
||||
@ -96,6 +97,7 @@ class FingerprintItemData {
|
||||
this.fingerprintId,
|
||||
this.senderUsername,
|
||||
this.weekDay,
|
||||
this.validTimeStr,
|
||||
this.cardName,
|
||||
this.cardNumber,
|
||||
this.cardType,
|
||||
@ -116,6 +118,7 @@ class FingerprintItemData {
|
||||
fingerprintId = json['fingerprintId'];
|
||||
senderUsername = json['senderUsername'];
|
||||
weekDay = json['weekDay'];
|
||||
validTimeStr = json['validTimeStr'];
|
||||
cardName = json['cardName'];
|
||||
cardNumber = json['cardNumber'];
|
||||
cardType = json['cardType'];
|
||||
@ -138,6 +141,7 @@ class FingerprintItemData {
|
||||
data['fingerprintId'] = fingerprintId;
|
||||
data['senderUsername'] = senderUsername;
|
||||
data['weekDay'] = weekDay;
|
||||
data['validTimeStr'] = validTimeStr;
|
||||
data['cardName'] = cardName;
|
||||
data['cardNumber'] = cardNumber;
|
||||
data['cardType'] = cardType;
|
||||
|
||||
@ -238,7 +238,7 @@ class FingerprintListLogic extends BaseGetXController{
|
||||
}
|
||||
// 获取指纹状态
|
||||
Future<void> senderQueryingFingerprintStatus() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName,(DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName,(DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -266,7 +266,7 @@ class FingerprintListLogic extends BaseGetXController{
|
||||
|
||||
// 查询用户、指纹、密码、卡片数量(用于判断是否同步)
|
||||
Future<void> senderCheckingUserInfoCount() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -293,7 +293,7 @@ class FingerprintListLogic extends BaseGetXController{
|
||||
|
||||
// 删除指纹
|
||||
Future<void> senderAddFingerprint() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
@ -144,9 +144,13 @@ class _FingerprintListPageState extends State<FingerprintListPage> {
|
||||
child: _keyItem(
|
||||
'images/icon_fingerprint.png',
|
||||
fingerprintItemData.fingerprintName!,
|
||||
fingerprintItemData.fingerprintType! == 1
|
||||
? "永久"
|
||||
: "${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())}",
|
||||
fingerprintItemData.endDate! < DateTime.now().millisecondsSinceEpoch
|
||||
? "已失效"
|
||||
: "",
|
||||
fingerprintItemData.validTimeStr!,
|
||||
// fingerprintItemData.fingerprintType! == 1
|
||||
// ? "永久"
|
||||
// : "${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())}",
|
||||
() async {
|
||||
var data = await Get.toNamed(
|
||||
Routers.fingerprintDetailPage,
|
||||
@ -218,7 +222,7 @@ class _FingerprintListPageState extends State<FingerprintListPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _keyItem(String lockTypeIcon, String lockTypeTitle, String showTime,
|
||||
Widget _keyItem(String lockTypeIcon, String lockTypeTitle, String ifInvalidation, String showTime,
|
||||
Function() action) {
|
||||
return GestureDetector(
|
||||
onTap: action,
|
||||
@ -240,11 +244,16 @@ class _FingerprintListPageState extends State<FingerprintListPage> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(lockTypeTitle,
|
||||
style: TextStyle(
|
||||
fontSize: 24.sp, color: AppColors.blackColor)),
|
||||
Expanded(child: Container()),
|
||||
Text(ifInvalidation,
|
||||
style: TextStyle(
|
||||
fontSize: 22.sp, color: Colors.red)),
|
||||
SizedBox(width: 10.w),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 5.h),
|
||||
|
||||
@ -128,7 +128,7 @@ class AutomaticBlockingLogic extends BaseGetXController{
|
||||
|
||||
// 读取支持功能-带参数
|
||||
Future<void> _readSupportFunctionsWithParameters() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -154,7 +154,7 @@ class AutomaticBlockingLogic extends BaseGetXController{
|
||||
|
||||
// 设置支持功能(带参数)
|
||||
Future<void> sendAutoLock() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -13,7 +13,7 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{
|
||||
|
||||
// 读取支持功能-带参数
|
||||
Future<void> _readAdminPassword() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -112,7 +112,7 @@ class BurglarAlarmLogic extends BaseGetXController{
|
||||
|
||||
// 读取支持功能-带参数
|
||||
Future<void> _readSupportFunctionsNoParameters() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -138,7 +138,7 @@ class BurglarAlarmLogic extends BaseGetXController{
|
||||
|
||||
// 设置支持功能(带参数)
|
||||
Future<void> sendBurglarAlarm() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -131,7 +131,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
|
||||
|
||||
// 点击配置wifi
|
||||
Future<void> senderConfiguringWifiAction() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected){
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -250,7 +250,7 @@ class LockSetLogic extends BaseGetXController {
|
||||
|
||||
// 删除用户
|
||||
Future<void> deletUserAction() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -281,7 +281,7 @@ class LockSetLogic extends BaseGetXController {
|
||||
|
||||
// 恢复出厂设置
|
||||
Future<void> factoryDataResetAction() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected){
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -335,7 +335,7 @@ class LockSetLogic extends BaseGetXController {
|
||||
|
||||
// 设置支持功能(带参数)
|
||||
Future<void> sendBurglarAlarm(int type) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -120,7 +120,7 @@ class LockSoundSetLogic extends BaseGetXController {
|
||||
|
||||
// 读取支持功能-带参数
|
||||
Future<void> _readSupportFunctionsWithParameters() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -146,7 +146,7 @@ class LockSoundSetLogic extends BaseGetXController {
|
||||
|
||||
// 设置支持功能(带参数)
|
||||
Future<void> sendLockSound() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -146,7 +146,7 @@ class LockTimeLogic extends BaseGetXController{
|
||||
|
||||
// 校验时间
|
||||
Future<void> sendTiming() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -111,7 +111,7 @@ class MotorPowerLogic extends BaseGetXController {
|
||||
|
||||
// 读取支持功能-带参数
|
||||
Future<void> _readSupportFunctionsNoParameters() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -137,7 +137,7 @@ class MotorPowerLogic extends BaseGetXController {
|
||||
|
||||
// 设置支持功能(带参数)
|
||||
Future<void> sendOpenDoorDirection() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -139,7 +139,7 @@ class NormallyOpenModeLogic extends BaseGetXController{
|
||||
|
||||
// 读取支持功能-带参数
|
||||
Future<void> _readSupportFunctionsWithParameters() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -165,7 +165,7 @@ class NormallyOpenModeLogic extends BaseGetXController{
|
||||
|
||||
// 设置支持功能(带参数)
|
||||
Future<void> sendAutoLock() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -113,7 +113,7 @@ class OpenDoorDirectionLogic extends BaseGetXController {
|
||||
|
||||
// 读取支持功能-带参数
|
||||
Future<void> _readSupportFunctionsNoParameters() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -139,7 +139,7 @@ class OpenDoorDirectionLogic extends BaseGetXController {
|
||||
|
||||
// 设置支持功能(带参数)
|
||||
Future<void> sendOpenDoorDirection() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -112,7 +112,7 @@ class RemoteUnlockingLogic extends BaseGetXController{
|
||||
|
||||
// 读取支持功能-带参数
|
||||
Future<void> _readSupportFunctionsNoParameters() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -138,7 +138,7 @@ class RemoteUnlockingLogic extends BaseGetXController{
|
||||
|
||||
// 设置支持功能(带参数)
|
||||
Future<void> sendBurglarAlarm() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -114,7 +114,7 @@ class ResetButtonLogic extends BaseGetXController{
|
||||
|
||||
// 读取支持功能-带参数
|
||||
Future<void> _readSupportFunctionsNoParameters() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -140,7 +140,7 @@ class ResetButtonLogic extends BaseGetXController{
|
||||
|
||||
// 设置支持功能(带参数)
|
||||
Future<void> sendBurglarAlarm() async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
||||
if (connectionState == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -349,7 +349,8 @@ class LockDetailLogic extends BaseGetXController{
|
||||
// Toast.show(msg: "正在连接设备,请稍等。");
|
||||
// return;
|
||||
// }
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async {
|
||||
print("77777777:$deviceConnectionState");
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -379,8 +380,14 @@ class LockDetailLogic extends BaseGetXController{
|
||||
signKey: signKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
}else if (deviceConnectionState == DeviceConnectionState.disconnected){
|
||||
// Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
|
||||
|
||||
state.lockState.value = 4;
|
||||
state.animationController.reset();
|
||||
state.animationController.forward();
|
||||
}
|
||||
}, isShowLoading: false, isShowToast: false);
|
||||
}, isShowLoading: false);
|
||||
}
|
||||
|
||||
// 编辑用户事件
|
||||
@ -420,32 +427,32 @@ class LockDetailLogic extends BaseGetXController{
|
||||
|
||||
|
||||
// 备用逻辑,进入管理钥匙界面获取锁状态
|
||||
Future<void> connectBlue(String bluetoothDeviceId, String bluetoothDeviceName) async {
|
||||
Future<void> connectBlue(String bluetoothDeviceName) async {
|
||||
// 进来之后首先连接
|
||||
BlueManage().connect(bluetoothDeviceId, bluetoothDeviceName, connectStateCallBack: (DeviceConnectionState state) async {
|
||||
BlueManage().connect(bluetoothDeviceName, (DeviceConnectionState state) async {
|
||||
if(EasyLoading.isShow){
|
||||
EasyLoading.dismiss();
|
||||
}
|
||||
if (state == DeviceConnectionState.connected){
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
// IoSenderManage.senderGetLockStatu(
|
||||
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
// // IoSenderManage.senderGetLockStatu(
|
||||
// // lockID:BlueManage().connectDeviceName,
|
||||
// // userID:await Storage.getUid(),
|
||||
// // privateKey:getPrivateKeyList,
|
||||
// // );
|
||||
// IoSenderManage.senderGetStarLockStatuInfo(
|
||||
// lockID:BlueManage().connectDeviceName,
|
||||
// userID:await Storage.getUid(),
|
||||
// privateKey:getPrivateKeyList,
|
||||
// );
|
||||
IoSenderManage.senderGetStarLockStatuInfo(
|
||||
lockID:BlueManage().connectDeviceName,
|
||||
userID:await Storage.getUid(),
|
||||
privateKey:getPrivateKeyList,
|
||||
);
|
||||
}
|
||||
}, isShowLoading: false);
|
||||
}
|
||||
|
||||
// 查询事件记录(时间查询)
|
||||
Future<void> senderReferEventRecordTime(int time) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -474,7 +481,7 @@ class LockDetailLogic extends BaseGetXController{
|
||||
// 添加用户(普通用户接收电子钥匙)
|
||||
Future<void> addUserConnectBlue() async {
|
||||
// 进来之后首先连接
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == DeviceConnectionState.connected){
|
||||
// 私钥
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
@ -509,44 +516,23 @@ class LockDetailLogic extends BaseGetXController{
|
||||
}, isShowLoading: false);
|
||||
}
|
||||
|
||||
void startScanAction(){
|
||||
BlueManage().startScan(true, (v){
|
||||
// print("startScanAllDevice:${v}");
|
||||
final knownDeviceIndex = v.indexWhere((d) => d.name == state.keyInfos.value.bluetooth!.bluetoothDeviceName!);
|
||||
// 当扫描到的时候
|
||||
if (knownDeviceIndex >= 0) {
|
||||
BlueManage().connectDeviceMacAddress = v[knownDeviceIndex].id;
|
||||
connectBlue(v[knownDeviceIndex].id, state.keyInfos.value.bluetooth!.bluetoothDeviceName!);
|
||||
eventBus.fire(ScanAllDeviceFindCurrentDeviceConnectedEvent(v[knownDeviceIndex].serviceUuids[0].toString()));
|
||||
BlueManage().stopScan();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//开始连接
|
||||
startConnect() {
|
||||
state.lockState.value = 1;
|
||||
state.animationController.forward();
|
||||
|
||||
if(state.lockUserNo == 0){
|
||||
// 电子钥匙lockUserNo为0 要先添加用户
|
||||
addUserConnectBlue();
|
||||
}else{
|
||||
if(state.isOpenLockNeedOnline.value == 0){
|
||||
// 不需要联网
|
||||
openDoorAction();
|
||||
}else{
|
||||
// 需要联网
|
||||
getLockNetToken();
|
||||
}
|
||||
}
|
||||
|
||||
Future.delayed(const Duration(seconds: 10), () {
|
||||
if(state.lockState.value == 1){
|
||||
stopConnect();
|
||||
state.lockState.value = 4;
|
||||
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
|
||||
state.animationController.reset();
|
||||
state.animationController.forward();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//关闭连接
|
||||
@ -618,33 +604,20 @@ class LockDetailLogic extends BaseGetXController{
|
||||
super.onReady();
|
||||
print("onReady()");
|
||||
|
||||
// List<int> model = [5, 3, 2, 16, 100, 176, 0, 244, 249, 83, 101, 223, 74, 100, 40, 228, 96];
|
||||
// var modelStr = utf8String(model);
|
||||
// print("modelStrmodelStrmodelStr:$modelStr");
|
||||
|
||||
_initReplySubscription();
|
||||
initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction();
|
||||
|
||||
EasyLoading.show(status: "正在连接设备,请稍等。", maskType: EasyLoadingMaskType.none, dismissOnTap: true);
|
||||
Future.delayed(const Duration(seconds: 12), () {
|
||||
if(EasyLoading.isShow){
|
||||
EasyLoading.dismiss();
|
||||
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
|
||||
}
|
||||
});
|
||||
|
||||
if(Platform.isIOS){
|
||||
print("有蓝牙权限开始扫描");
|
||||
startScanAction();
|
||||
}else{
|
||||
getMicrophonePermission()
|
||||
.then((value) {
|
||||
if (value) {
|
||||
// 有权限
|
||||
print("有蓝牙权限开始扫描");
|
||||
startScanAction();
|
||||
}else{
|
||||
//没有权限
|
||||
openAppSettings();//打开app系统设置
|
||||
}
|
||||
});
|
||||
}
|
||||
// EasyLoading.show(status: "正在连接设备,请稍等。", maskType: EasyLoadingMaskType.none, dismissOnTap: true);
|
||||
// Future.delayed(const Duration(seconds: 12), () {
|
||||
// if(EasyLoading.isShow){
|
||||
// EasyLoading.dismiss();
|
||||
// Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
@override
|
||||
@ -658,24 +631,6 @@ class LockDetailLogic extends BaseGetXController{
|
||||
// factoryDataResetAction();
|
||||
}
|
||||
|
||||
///请求录音相机权限
|
||||
Future<bool> getMicrophonePermission() async {
|
||||
// You can request multiple permissions at once.
|
||||
Map<Permission, PermissionStatus> statuses = await [
|
||||
Permission.bluetoothScan,
|
||||
Permission.bluetoothConnect,
|
||||
Permission.location,
|
||||
].request();
|
||||
|
||||
//granted 通过,denied 被拒绝,permanentlyDenied 拒绝且不在提示
|
||||
if (statuses[Permission.bluetoothScan]!.isGranted &&
|
||||
statuses[Permission.bluetoothConnect]!.isGranted &&
|
||||
statuses[Permission.location]!.isGranted) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
|
||||
@ -124,7 +124,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
child: Obx(() => Stack(
|
||||
children: [
|
||||
Image.asset(
|
||||
state.lockState.value == 4 ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png',
|
||||
(state.lockState.value == 4 || state.lockState.value == 0) ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png',
|
||||
width: 330.w,
|
||||
height: 330.w,
|
||||
),
|
||||
@ -290,7 +290,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
|
||||
// 设置
|
||||
bottomItem('images/main/icon_main_set.png', TranslationLoader.lanKeys!.set!.tr, () {
|
||||
BlueManage().stopScan();
|
||||
// BlueManage().stopScan();
|
||||
Get.toNamed(Routers.lockSetPage,
|
||||
arguments: {"lockId": widget.lockListInfoItemEntity.lockId});
|
||||
}),
|
||||
@ -406,7 +406,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
}),
|
||||
// 设置
|
||||
bottomItem('images/main/icon_main_set.png', TranslationLoader.lanKeys!.set!.tr, () {
|
||||
BlueManage().stopScan();
|
||||
// BlueManage().stopScan();
|
||||
Get.toNamed(Routers.lockSetPage,
|
||||
arguments: {"lockId": widget.lockListInfoItemEntity.lockId});
|
||||
}),
|
||||
@ -452,8 +452,10 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
state.animationController.addStatusListener((status) {
|
||||
print("AnimationStatus:$status");
|
||||
if (status == AnimationStatus.completed) {
|
||||
state.animationController.reset();
|
||||
state.animationController.forward();
|
||||
} else if (status == AnimationStatus.dismissed) {
|
||||
state.animationController.reset();
|
||||
state.animationController.forward();
|
||||
}
|
||||
});
|
||||
@ -500,7 +502,6 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
// AppRouteObserver().routeObserver.unsubscribe(this);
|
||||
state.animationController.dispose();
|
||||
super.dispose();
|
||||
BlueManage().stopScan();
|
||||
BlueManage().disconnect(BlueManage().connectDeviceMacAddress);
|
||||
}
|
||||
|
||||
|
||||
@ -159,7 +159,7 @@ class LockOperatingRecordLogic extends BaseGetXController{
|
||||
|
||||
// 查询事件记录(时间查询)
|
||||
Future<void> senderReferEventRecordTime(int time) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
@ -223,9 +223,7 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
|
||||
|
||||
// 设置自定义密码
|
||||
Future<void> senderCustomPasswords() async {
|
||||
BlueManage().judgeReconnect(
|
||||
BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName,
|
||||
(DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
@ -15,6 +15,7 @@ import 'package:amap_flutter_base/amap_flutter_base.dart';
|
||||
|
||||
import '../../../../appRouters.dart';
|
||||
import '../../../../app_settings/app_colors.dart';
|
||||
import '../../../../blue/blue_manage.dart';
|
||||
import '../../../../tools/titleAppBar.dart';
|
||||
import '../../../../tools/toast.dart';
|
||||
import '../../../../translations/trans_lib.dart';
|
||||
@ -363,6 +364,9 @@ class _LockAddressGaoDePageState extends State<LockAddressGaoDePage>{
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
|
||||
BlueManage().disconnect(BlueManage().connectDeviceMacAddress);
|
||||
|
||||
location.stopLocation();
|
||||
location.destroy();
|
||||
print("地图界面销毁了");
|
||||
|
||||
@ -35,7 +35,9 @@ class NearbyLockLogic extends BaseGetXController{
|
||||
// IoSenderManage.getPublicKey(lockId: deviceName);
|
||||
// }
|
||||
// }, isShowLoading: true);
|
||||
BlueManage().connect(lockId, deviceName, isFrist: true, isShowLoading: true);
|
||||
BlueManage().connect(deviceName, (state){
|
||||
|
||||
}, isFrist: true, isShowLoading: true);
|
||||
}
|
||||
|
||||
// 获取解析后的数据
|
||||
@ -313,7 +315,7 @@ class NearbyLockLogic extends BaseGetXController{
|
||||
Future<void> _getStarLockStatus() async {
|
||||
// print("connectDeviceMacAddress:${BlueManage().connectDeviceMacAddress} connectDeviceName:${BlueManage().connectDeviceName}");
|
||||
// 进来之后首先连接
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
@ -331,6 +333,19 @@ class NearbyLockLogic extends BaseGetXController{
|
||||
}, isShowLoading: false);
|
||||
}
|
||||
|
||||
late StreamSubscription<List<DiscoveredDevice>> _scanListDiscoveredDeviceSubscription;
|
||||
void _scanListDiscoveredDeviceSubscriptionAction() {
|
||||
_scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on<List<DiscoveredDevice>>().listen((List<DiscoveredDevice> 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")){
|
||||
state.devices.add(list[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
@ -338,6 +353,7 @@ class NearbyLockLogic extends BaseGetXController{
|
||||
print("NearbyLockLogic onReady()");
|
||||
|
||||
_initReplySubscription();
|
||||
_scanListDiscoveredDeviceSubscriptionAction();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -345,12 +361,6 @@ class NearbyLockLogic extends BaseGetXController{
|
||||
// TODO: implement onInit
|
||||
super.onInit();
|
||||
print("NearbyLockLogic onInit()");
|
||||
|
||||
// 进来第一步开始扫描
|
||||
BlueManage().startScan(false ,(v){
|
||||
state.devices.clear();
|
||||
state.devices.addAll(v);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@ -358,6 +368,7 @@ class NearbyLockLogic extends BaseGetXController{
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
_replySubscription.cancel();
|
||||
_scanListDiscoveredDeviceSubscription.cancel();
|
||||
// BlueManage().stopScan();
|
||||
}
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ class SaveLockLogic extends BaseGetXController {
|
||||
// 添加用户
|
||||
Future<void> addUserConnectBlue() async {
|
||||
// 进来之后首先连接
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||
if (state == DeviceConnectionState.connected){
|
||||
// 私钥
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user