优化蓝牙功能

This commit is contained in:
魏少阳 2023-12-27 10:47:58 +08:00
parent b3ee82d605
commit 16d5d53c61
37 changed files with 320 additions and 363 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -89,6 +89,8 @@ class AddCardTypeLogic extends BaseGetXController{
});
}
@override
void onInit() {
super.onInit();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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("地图界面销毁了");

View File

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

View File

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