重构蓝牙逻辑

This commit is contained in:
魏少阳 2024-01-02 18:03:50 +08:00
parent 0225a1c464
commit 69de4e0ac6
30 changed files with 274 additions and 212 deletions

View File

@ -3,9 +3,7 @@ import 'dart:async';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:star_lock/blue/sender_manage.dart';
import '../tools/toast.dart';
import 'io_tool/io_model.dart';
import 'io_tool/io_tool.dart';
import 'io_tool/manager_event_bus.dart';
@ -19,7 +17,9 @@ class BlueManage{
final List<DiscoveredDevice> scanDevices = [];
// id
Uuid serviceId = Uuid.parse('0000FFF0-0000-1000-8000-00805F9B34FB');
Uuid serviceIdConnect = Uuid.parse("fff0");
// id
Uuid serviceIdWrite = Uuid.parse('0000FFF0-0000-1000-8000-00805F9B34FB');
// id
Uuid characteristicIdSubscription = Uuid.parse("fff1");
// id
@ -52,8 +52,8 @@ class BlueManage{
BlueManage? get manager => shareManager();
void _initBlue(){
// print("蓝牙功能初始化了");
_flutterReactiveBle ??= FlutterReactiveBle();
print("蓝牙功能初始化了");
_initSendStreamSubscription();
}
@ -92,8 +92,19 @@ class BlueManage{
});
}
///
Future<void> judgeReconnect(String deviceName, ConnectStateCallBack stateCallBack) async {
if(deviceConnectionState != DeviceConnectionState.connected){
_connect(deviceName, (state){
stateCallBack(deviceConnectionState!);
});
}else{
stateCallBack(deviceConnectionState!);
}
}
///
Future<void> connect(String deviceName, ConnectStateCallBack connectStateCallBack, {bool? isFrist = false ,bool isShowLoading = true}) async {
Future<void> _connect(String deviceName, ConnectStateCallBack connectStateCallBack) async {
connectDeviceName = deviceName;
//
final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName);
@ -107,15 +118,15 @@ class BlueManage{
Completer? completer = Completer();
Timer.periodic(const Duration(milliseconds: 1000), (timer) {
///
print("timer index:$index");
if(index >= 4){
// print("timer index0:$index");
if(index >= 5){
// 5
completer.complete();
timer.cancel();
connectDeviceMacAddress = "";
deviceConnectionState = DeviceConnectionState.disconnected;
connectStateCallBack(deviceConnectionState!);
Toast.show(msg: "未扫描到要连接的设备,请确保在设备附近,设备未被连接,设备已打开");
// deviceConnectionState = DeviceConnectionState.disconnected;
// print("timer index1:$index");
connectStateCallBack(DeviceConnectionState.disconnected);
}else{
//
final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName);
@ -123,6 +134,7 @@ class BlueManage{
//
completer.complete();
timer.cancel();
// print("timer index2:$index");
connectDeviceMacAddress = scanDevices[knownDeviceIndex].id;
} else {
// -1 5
@ -133,7 +145,6 @@ class BlueManage{
});
// Completer完成
await completer.future;
// print("111111");
}
print("connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName");
@ -141,21 +152,20 @@ class BlueManage{
return;
}
_currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(milliseconds: 10000)).listen((connectionStateUpdate) async {
_currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(seconds: 10)).listen((connectionStateUpdate) async {
//
deviceConnectionState = connectionStateUpdate.connectionState;
print('deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}');
if(connectionStateUpdate.connectionState == DeviceConnectionState.connected){
//
try {
_subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: characteristicIdSubscription, serviceId: Uuid.parse("fff0"), deviceId: connectDeviceMacAddress));
_subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: characteristicIdSubscription, serviceId: serviceIdConnect, deviceId: connectDeviceMacAddress));
print('Discovering services finished');
if(isFrist == true){
//
IoSenderManage.getPublicKey(lockId: deviceName);
}
// print("333333:$deviceConnectionState");
// if(isFrist == true){
// //
// IoSenderManage.getPublicKey(lockId: deviceName);
// }
deviceConnectionState = connectionStateUpdate.connectionState;
connectStateCallBack(deviceConnectionState!);
} on Exception catch (e) {
@ -177,17 +187,6 @@ class BlueManage{
);
}
//
Future<void> judgeReconnect(String deviceName, ConnectStateCallBack stateCallBack, {bool isShowLoading = true}) async {
if(deviceConnectionState != DeviceConnectionState.connected){
connect(deviceName, (state){
stateCallBack(deviceConnectionState!);
}, isShowLoading: false);
}else{
stateCallBack(deviceConnectionState!);
}
}
// ,
var allData = <int>[];
_subScribeToCharacteristic(QualifiedCharacteristic characteristic) {
@ -231,8 +230,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)}');
QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: characteristicIdWrite, serviceId: serviceIdWrite, deviceId: connectDeviceMacAddress);
int mtuLength = await _flutterReactiveBle!.requestMtu(deviceId: characteristic.deviceId, mtu: 250);
print("mtuLength:$mtuLength");
try {
@ -257,7 +255,7 @@ class BlueManage{
}
//
Future<List<int>> readCharacteristic(QualifiedCharacteristic characteristic) async {
Future<List<int>> _readCharacteristic(QualifiedCharacteristic characteristic) async {
try {
final result = await _flutterReactiveBle!.readCharacteristic(characteristic);
print("readListresult$result");
@ -281,10 +279,10 @@ class BlueManage{
}
//
Future<void> stopScan() async {
await _scanSubscription?.cancel();
_scanSubscription = null;
}
// Future<void> stopScan() async {
// await _scanSubscription?.cancel();
// _scanSubscription = null;
// }
//
Future<void> disconnect(String deviceMAC) async {
@ -295,7 +293,6 @@ class BlueManage{
print("Error disconnecting from a device: $e");
} finally {
deviceConnectionState = DeviceConnectionState.disconnected;
// _currentConnectionStream = null;
}
}

View File

@ -59,18 +59,6 @@ class OpenLockCommand extends SenderProtocol {
// OpenTime 4
int? d1 = openTime;
// var testData = [];
// testData.add((d1! & 0xff000000) >> 24);
// testData.add((d1 & 0xff0000) >> 16);
// testData.add((d1 & 0xff00) >> 8);
// testData.add((d1 & 0xff));
//
// int value = (
// (0xff & testData[(0)]) << 24 |
// (0xff & testData[1]) << 16 |
// (0xff & testData[2]) << 8 |
// (0xFF & testData[3]));
// print("d1:$d1 testData:$testData value$value");
data.add((d1! & 0xff000000) >> 24);
data.add((d1 & 0xff0000) >> 16);

View File

@ -240,6 +240,9 @@ class AddICCardLogic extends BaseGetXController{
privateKey:getPrivateKeyList,
token: getTokenList,
);
} else if (deviceConnectionState == DeviceConnectionState.disconnected){
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
Get.close(2);
}
});
}

View File

@ -255,7 +255,7 @@ class CardListLogic extends BaseGetXController {
privateKey:getPrivateKeyList,
);
}
}, isShowLoading: false);
});
}
//

View File

@ -280,7 +280,7 @@ class AddFingerprintLogic extends BaseGetXController {
token: getTokenList,
);
}else if (deviceConnectionState == DeviceConnectionState.disconnected){
// Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
Get.close(2);
}
});

View File

@ -288,7 +288,7 @@ class FingerprintListLogic extends BaseGetXController{
privateKey:getPrivateKeyList,
);
}
}, isShowLoading: false);
});
}
//

View File

@ -154,8 +154,10 @@ class AutomaticBlockingLogic extends BaseGetXController{
// ()
Future<void> sendAutoLock() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -186,6 +188,9 @@ class AutomaticBlockingLogic extends BaseGetXController{
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
} else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}

View File

@ -9,6 +9,7 @@ import '../../../../app_settings/app_colors.dart';
import '../../../../tools/commonItem.dart';
import '../../../../tools/showBottomSheetTool.dart';
import '../../../../tools/titleAppBar.dart';
import '../../../../tools/toast.dart';
import '../../../../translations/trans_lib.dart';
import 'automaticBlocking_logic.dart';
@ -40,6 +41,10 @@ class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> {
if(state.isJustForShow.value == true){
return;
}
if(state.isCustomLockTime.value == true && state.timeController.text.isEmpty){
Toast.show(msg: "请输入自定义时间");
return;
}
logic.sendAutoLock();
},
)),
@ -120,7 +125,7 @@ class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> {
maxLines: 1,
controller: state.timeController,
autofocus: false,
readOnly: state.isJustForShow.value == true ? false : true,
readOnly: state.isJustForShow.value == true ? true : false,
decoration: InputDecoration(
//
contentPadding:

View File

@ -26,7 +26,7 @@ class BurglarAlarmLogic extends BaseGetXController{
antiPrySwitch:state.burglarAlarmEnable.value == 1 ? 0 : 1, // 1-2-;
);
if(entity.errorCode!.codeIsSuccessful){
eventBus.fire(RefreshLockListInfoDataEvent());
// eventBus.fire(RefreshLockListInfoDataEvent());
state.burglarAlarmEnable.value = state.burglarAlarmEnable.value == 1 ? 0 : 1;
state.lockSetInfoData.value.lockSettingInfo!.antiPrySwitch = state.burglarAlarmEnable.value;
@ -138,8 +138,10 @@ class BurglarAlarmLogic extends BaseGetXController{
// ()
Future<void> sendBurglarAlarm() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -158,6 +160,9 @@ class BurglarAlarmLogic extends BaseGetXController{
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
} else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}

View File

@ -131,7 +131,9 @@ class ConfiguringWifiLogic extends BaseGetXController{
// wifi
Future<void> senderConfiguringWifiAction() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
dismissEasyLoading();
if (connectionState == DeviceConnectionState.connected){
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -172,7 +174,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
privateKey: getPrivateKeyList,
);
}
}, isShowLoading: true);
});
}
final _networkInfo = NetworkInfo();

View File

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:get/get.dart';
import 'package:star_lock/blue/io_protocol/io_deletUser.dart';
@ -18,6 +19,7 @@ import '../../../../blue/sender_manage.dart';
import '../../../../network/api_repository.dart';
import '../../../../tools/baseGetXController.dart';
import '../../../../tools/eventBusEventManage.dart';
import '../../../../tools/showTFView.dart';
import '../../../../tools/storage.dart';
import '../../../../tools/toast.dart';
import '../../../../translations/trans_lib.dart';
@ -251,38 +253,40 @@ class LockSetLogic extends BaseGetXController {
//
Future<void> deletUserAction() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
var token = await Storage.getStringList(saveBlueToken);
List<int> getTokenList = changeStringListToIntList(token!);
var token = await Storage.getStringList(saveBlueToken);
List<int> getTokenList = changeStringListToIntList(token!);
IoSenderManage.deletUser(
lockID: BlueManage().connectDeviceName,
authUserID:state.lockBasicInfo.value.senderUserId.toString(),
keyID:state.lockBasicInfo.value.keyId.toString(),
delUserID:await Storage.getUid(),
// authUserID: "100001",
// keyID: "1",
// delUserID: "100001",
needAuthor: 1,
publicKey: publicKeyDataList,
privateKey: getPrivateKeyList,
token: getTokenList);
}else{
showDeletAlertTipDialog(Get.context!);
}
});
IoSenderManage.deletUser(
lockID: BlueManage().connectDeviceName,
authUserID:state.lockBasicInfo.value.senderUserId.toString(),
keyID:state.lockBasicInfo.value.keyId.toString(),
delUserID:await Storage.getUid(),
// authUserID: "100001",
// keyID: "1",
// delUserID: "100001",
needAuthor: 1,
publicKey: publicKeyDataList,
privateKey: getPrivateKeyList,
token: getTokenList);
} else if (connectionState == DeviceConnectionState.disconnected) {
showDeletAlertTipDialog(Get.context!);
}
});
}
//
Future<void> factoryDataResetAction() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected){
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected){
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -301,7 +305,8 @@ class LockSetLogic extends BaseGetXController {
privateKey:getPrivateKeyList,
token: getTokenList
);
}else{
} else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showDeletAlertTipDialog(Get.context!);
}
});
@ -335,8 +340,10 @@ class LockSetLogic extends BaseGetXController {
// ()
Future<void> sendBurglarAlarm(int type) async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -371,6 +378,9 @@ class LockSetLogic extends BaseGetXController {
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
} else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}
@ -421,30 +431,45 @@ class LockSetLogic extends BaseGetXController {
}
}
void showDeletPasswordAlertDialog(BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) {
return ShowTFView(
title: "请输入登录密码",
tipTitle: "",
controller: state.passwordTF,
sureClick: () {
//
if (state.passwordTF.text.isEmpty) {
Toast.show(msg: "请输入登录密码");
return;
}
checkLoginPassword();
},
cancelClick: () {
Get.back();
},
);
},
);
}
//
void checkLoginPassword(BlockDeletNumberCheckPasswordCallback blockDeletNumberCheckPasswordCallback) async {
void checkLoginPassword() async {
var entity = await ApiRepository.to.checkLoginPassword(
password: state.passwordTF.text,
);
if (entity.errorCode!.codeIsSuccessful) {
// deletLockInfoData();
// blockDeletNumberCheckPasswordCallback();
Get.back();
blockDeletNumberCheckPasswordCallback();
// if(state.currentDeviceUUid.value.isEmpty){
// Toast.show(msg: "未扫描到当前设备,请确保您在设备旁边、设备已开启、设备未被其他人连接");
// return;
// }
// if(state.currentDeviceUUid.value[31] == "1"){
//
if(state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1){
//
if(BlueManage().connectDeviceMacAddress.isNotEmpty){
//
factoryDataResetAction();
}else{
showDeletAlertTipDialog(Get.context!);
}
//
factoryDataResetAction();
}else{
//
if(BlueManage().connectDeviceMacAddress.isNotEmpty){

View File

@ -811,8 +811,8 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
CupertinoDialogAction(
child: Text(TranslationLoader.lanKeys!.sure!.tr),
onPressed: () {
Navigator.pop(context);
showDeletPasswordAlertDialog(context);
Get.back();
logic.showDeletPasswordAlertDialog(context);
},
),
],
@ -844,34 +844,6 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
// );
// }
void showDeletPasswordAlertDialog(
BuildContext context,
) {
showDialog(
context: context,
builder: (BuildContext context) {
return ShowTFView(
title: "请输入登录密码",
tipTitle: "",
controller: state.passwordTF,
sureClick: () {
//
if (state.passwordTF.text.isEmpty) {
Toast.show(msg: "请输入登录密码");
return;
}
logic.checkLoginPassword(() {
Navigator.pop(context);
});
},
cancelClick: () {
Navigator.pop(context);
},
);
},
);
}
@override
void didChangeDependencies() {
// TODO: implement didChangeDependencies

View File

@ -29,7 +29,7 @@ class LockSoundSetLogic extends BaseGetXController {
);
if(entity.errorCode!.codeIsSuccessful){
eventBus.fire(RefreshLockListInfoDataEvent());
// eventBus.fire(RefreshLockListInfoDataEvent());
state.lockSetInfoData.value.lockSettingInfo!.lockSound = state.isOpenLockSound.value == true ? 1 :2;
state.lockSetInfoData.value.lockSettingInfo!.lockSoundVolume = state.lockSoundLevel.value;
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
@ -146,8 +146,10 @@ class LockSoundSetLogic extends BaseGetXController {
// ()
Future<void> sendLockSound() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -175,6 +177,9 @@ class LockSoundSetLogic extends BaseGetXController {
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
} else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}

View File

@ -146,8 +146,10 @@ class LockTimeLogic extends BaseGetXController{
//
Future<void> sendTiming() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -166,6 +168,9 @@ class LockTimeLogic extends BaseGetXController{
signKey:getSignKeyList,
privateKey:getPrivateKeyList,
);
} else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}
@ -181,14 +186,16 @@ class LockTimeLogic extends BaseGetXController{
}
//
void getServerDatetime() async{
void getServerDatetime(bool isSendBlue) async{
var entity = await ApiRepository.to.getServerDatetimeData(
lockId: state.lockSetInfoData.value.lockId.toString(),
);
if(entity.errorCode!.codeIsSuccessful){
String dataEime = DateTool().dateToYMDHNSString("${entity.data!.date!}");
state.dateTime.value = dataEime;
sendTiming();
if(isSendBlue){
sendTiming();
}
}
}
@ -200,7 +207,7 @@ class LockTimeLogic extends BaseGetXController{
_initReplySubscription();
// getLockTimeFromGateway();
getServerDatetime();
getServerDatetime(false);
}
@override

View File

@ -53,8 +53,9 @@ class _LockTimePageState extends State<LockTimePage> {
padding: EdgeInsets.only(top: 20.w, bottom: 20.w),
onClick: () {
// print("1111111");
logic.sendTiming();
// logic.sendTiming();
// logic.getServerDatetime();
logic.getServerDatetime(true);
}),
SizedBox(
height: 40.h,

View File

@ -165,8 +165,10 @@ class NormallyOpenModeLogic extends BaseGetXController{
// ()
Future<void> sendAutoLock() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -194,6 +196,9 @@ class NormallyOpenModeLogic extends BaseGetXController{
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
} else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}

View File

@ -139,7 +139,9 @@ class OpenDoorDirectionLogic extends BaseGetXController {
// ()
Future<void> sendOpenDoorDirection() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
dismissEasyLoading();
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -159,6 +161,9 @@ class OpenDoorDirectionLogic extends BaseGetXController {
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
}else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}

View File

@ -133,11 +133,12 @@ class RemoteUnlockingLogic extends BaseGetXController{
privateKey: getPrivateKeyList
);
}
}, isShowLoading: true);
});
}
// ()
// ()
Future<void> sendBurglarAlarm() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey);
@ -158,6 +159,9 @@ class RemoteUnlockingLogic extends BaseGetXController{
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
} else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}

View File

@ -28,7 +28,7 @@ class ResetButtonLogic extends BaseGetXController{
resetSwitch:state.resetButtonEnable.value == 1 ? 0 : 1,
);
if(entity.errorCode!.codeIsSuccessful){
eventBus.fire(RefreshLockListInfoDataEvent());
// eventBus.fire(RefreshLockListInfoDataEvent());
state.resetButtonEnable.value = state.resetButtonEnable.value == 1 ? 2 : 1;
state.lockSetInfoData.value.lockSettingInfo!.resetSwitch = state.resetButtonEnable.value;
@ -140,8 +140,10 @@ class ResetButtonLogic extends BaseGetXController{
// ()
Future<void> sendBurglarAlarm() async {
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
if (connectionState == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -160,6 +162,9 @@ class ResetButtonLogic extends BaseGetXController{
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
} else if (connectionState == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}

View File

@ -2,6 +2,7 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:permission_handler/permission_handler.dart';
@ -345,12 +346,7 @@ class LockDetailLogic extends BaseGetXController{
//
Future<void> openDoorAction() async {
// if(BlueManage().connectDeviceMacAddress.isEmpty){
// Toast.show(msg: "正在连接设备,请稍等。");
// return;
// }
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!);
@ -368,7 +364,6 @@ class LockDetailLogic extends BaseGetXController{
}
print("openDoorTokenPubToken:$getTokenList getPrivateKeyList:$getPrivateKeyList");
print("millisecondsSinceEpoch/1000:${DateTime.now().millisecondsSinceEpoch~/1000}");
IoSenderManage.senderOpenLock(
keyID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
@ -381,13 +376,13 @@ class LockDetailLogic extends BaseGetXController{
privateKey: getPrivateKeyList,
);
}else if (deviceConnectionState == DeviceConnectionState.disconnected){
// Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
state.lockState.value = 4;
state.animationController.reset();
state.animationController.forward();
}
}, isShowLoading: false);
});
}
//
@ -427,28 +422,28 @@ class LockDetailLogic extends BaseGetXController{
//
Future<void> connectBlue(String bluetoothDeviceName) 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(
// // lockID:BlueManage().connectDeviceName,
// // userID:await Storage.getUid(),
// // privateKey:getPrivateKeyList,
// // );
// IoSenderManage.senderGetStarLockStatuInfo(
// lockID:BlueManage().connectDeviceName,
// userID:await Storage.getUid(),
// privateKey:getPrivateKeyList,
// );
}
}, isShowLoading: false);
}
// Future<void> _connectBlue(String bluetoothDeviceName) 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(
// // // 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 {
@ -475,7 +470,7 @@ class LockDetailLogic extends BaseGetXController{
privateKey:getPrivateKeyList,
);
}
}, isShowLoading: false);
});
}
// ()
@ -513,12 +508,18 @@ class LockDetailLogic extends BaseGetXController{
token: getTokenList
);
}
}, isShowLoading: false);
});
}
//
startConnect() {
state.lockState.value = 1;
if(state.lockState.value == 4){
// 4
state.lockState.value = 3;
}else{
//
state.lockState.value = 1;
}
state.animationController.forward();
if(state.lockUserNo == 0){
@ -535,10 +536,6 @@ class LockDetailLogic extends BaseGetXController{
}
}
//
stopConnect() {
}
// token
void getLockNetToken() async {
@ -581,6 +578,22 @@ class LockDetailLogic extends BaseGetXController{
}
}
// connectBlueAndAnimationController(){
// state.lockState.value = 1;
// state.animationController.forward();
// BlueManage().judgeReconnect(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async {
// if (deviceConnectionState == DeviceConnectionState.connected){
// state.lockState.value = 2;
// }else if (deviceConnectionState == DeviceConnectionState.disconnected){
// Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
//
// state.lockState.value = 4;
// state.animationController.reset();
// state.animationController.forward();
// }
// });
// }
///
StreamSubscription? _lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent;
void initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction() {
@ -604,31 +617,18 @@ 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: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
// }
// });
}
@override
void onInit() {
// TODO: implement onInit
super.onInit();
// print("lockDetail_onInit()");
//
// connectBlue();
// factoryDataResetAction();
}
@override

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
@ -124,7 +125,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
child: Obx(() => Stack(
children: [
Image.asset(
(state.lockState.value == 4 || state.lockState.value == 0) ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png',
(state.lockState.value == 4 || state.lockState.value == 3) ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png',
width: 330.w,
height: 330.w,
),
@ -372,9 +373,6 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
if (state.keyInfos.value.lockFeature!.videoIntercom == 1) {
showWidgetArr.add(
bottomItem('images/main/icon_catEyes.png', TranslationLoader.lanKeys!.monitoring!.tr, () {
// Navigator.pushNamed(context, Routers.otherTypeKeyListPage,
// arguments: 1);
// Toast.show(msg: "功能暂未开放");
Get.toNamed(Routers.lockMonitoringPage, arguments: {
"lockId": widget.lockListInfoItemEntity.lockId
});
@ -443,14 +441,14 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
);
}
listeningAnimations() {
Future.delayed(Duration.zero, () {
listeningAnimations() async {
await Future.delayed(Duration.zero, () {
state.animationController = AnimationController(
duration: const Duration(seconds: 20), vsync: this);
state.animationController.repeat();
//StatusListener
state.animationController.addStatusListener((status) {
print("AnimationStatus:$status");
// print("AnimationStatus:$status");
if (status == AnimationStatus.completed) {
state.animationController.reset();
state.animationController.forward();
@ -460,6 +458,8 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
}
});
});
// logic.connectBlueAndAnimationController();
}
String showElectricIcon (int electricnumber){

View File

@ -26,5 +26,5 @@ class LockDetailState {
//
late AnimationController animationController;
var lockState = 0.obs;// 0 1() 2 3 4
var lockState = 0.obs;// 0 1() 2 3 4 5
}

View File

@ -28,16 +28,16 @@ class NearbyLockLogic extends BaseGetXController{
final NearbyLockState state = NearbyLockState();
//
void connect(String lockId, String deviceName){
// BlueManage().stopScan();
// BlueManage().judgeReconnect(lockId, deviceName, (DeviceConnectionState state) async {
// if (state == DeviceConnectionState.connected) {
// IoSenderManage.getPublicKey(lockId: deviceName);
// }
// }, isShowLoading: true);
BlueManage().connect(deviceName, (state){
}, isFrist: true, isShowLoading: true);
void connect(String deviceName){
showEasyLoading();
BlueManage().judgeReconnect(deviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
IoSenderManage.getPublicKey(lockId: deviceName);
}else if (state == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}
//
@ -317,6 +317,7 @@ class NearbyLockLogic extends BaseGetXController{
//
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
dismissEasyLoading();
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
// IoSenderManage.senderGetLockStatu(
@ -329,8 +330,10 @@ class NearbyLockLogic extends BaseGetXController{
userID:await Storage.getUid(),
privateKey:getPrivateKeyList,
);
} else if (state == DeviceConnectionState.disconnected) {
dismissEasyLoading();
}
}, isShowLoading: false);
});
}
late StreamSubscription<List<DiscoveredDevice>> _scanListDiscoveredDeviceSubscription;

View File

@ -55,7 +55,7 @@ class _NearbyLockPageState extends State<NearbyLockPage> {
// logic.getPublicKey(state.devices[index].serviceUuids[0].toString());
state.seletLockName.value = state.devices[index].name;
// print("connect-lockId:${state.devices[index].id} deviceName:${state.devices[index].name}");
logic.connect(state.devices[index].id, state.devices[index].name);
logic.connect(state.devices[index].name);
// Get.toNamed(Routers.lockAddressGaoDePage);
});
},

View File

@ -98,15 +98,17 @@ class SaveLockLogic extends BaseGetXController {
}
//
saveLockAction(){
addUserConnectBlue();
}
// saveLockAction(){
// addUserConnectBlue();
// }
//
Future<void> addUserConnectBlue() async {
//
showEasyLoading();
BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected){
dismissEasyLoading();
//
var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -136,12 +138,15 @@ class SaveLockLogic extends BaseGetXController {
privateKey:getPrivateKeyList,
token: getTokenList
);
} else if (state == DeviceConnectionState.disconnected) {
dismissEasyLoading();
showBlueConnetctToast();
}
});
}
void bindBlueAdmin() async{
print("state.lockInfo:${state.lockInfo}");
// print("state.lockInfo:${state.lockInfo}");
var positionMap = {};
positionMap['longitude'] = state.addressInfo["longitude"];

View File

@ -101,7 +101,7 @@ class _SaveLockPageState extends State<SaveLockPage> {
),
onClick: (){
// Navigator.pop(context);
logic.saveLockAction();
logic.addUserConnectBlue();
}
),
],

View File

@ -53,7 +53,7 @@ class MineSetLogic extends BaseGetXController {
LoginEntity entity = await ApiRepository.to.userLogout();
if (entity.errorCode!.codeIsSuccessful) {
logOut();
BlueManage().stopScan();
// BlueManage().stopScan();
BlueManage().disconnect(BlueManage().connectDeviceMacAddress);
Get.offNamedUntil(Routers.starLockLoginPage, (route) => false);
}

View File

@ -54,6 +54,10 @@ class BaseGetXController extends GetxController{
void dismissEasyLoading() => EasyLoading.dismiss();
void showBlueConnetctToast() {
showToast("未扫描到要连接的设备,请确保在设备附近,设备未被连接,设备已打开");
}
void showToast(String status,{Function? something}) {
EasyLoading.showToast(status,duration: 2000.milliseconds);
if(something != null) {

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class TitleAppBar extends AppBar {
@ -45,7 +46,16 @@ class _TitleAppBarState extends State<TitleAppBar> {
? IconButton(
icon: Icon(Icons.arrow_back_ios,
color: widget.iconColor ?? Colors.white),
onPressed: () => widget.backAction ?? Navigator.of(context).pop(),
onPressed: () {
if (widget.backAction != null) {
widget.backAction!();
} else {
if(EasyLoading.isShow){
EasyLoading.dismiss();
}
Navigator.pop(context);
}
}
)
: Container()),
backgroundColor: widget.backgroundColor ?? Colors.white,

View File

@ -22,6 +22,12 @@ class Toast{
);
}
///
///
static hidden(){
ToastPlugins.Fluttertoast.cancel();
}
///
/// context:
/// title