重构蓝牙逻辑
This commit is contained in:
parent
0225a1c464
commit
69de4e0ac6
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -240,6 +240,9 @@ class AddICCardLogic extends BaseGetXController{
|
||||
privateKey:getPrivateKeyList,
|
||||
token: getTokenList,
|
||||
);
|
||||
} else if (deviceConnectionState == DeviceConnectionState.disconnected){
|
||||
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
|
||||
Get.close(2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ class CardListLogic extends BaseGetXController {
|
||||
privateKey:getPrivateKeyList,
|
||||
);
|
||||
}
|
||||
}, isShowLoading: false);
|
||||
});
|
||||
}
|
||||
|
||||
// 删除卡片
|
||||
|
||||
@ -280,7 +280,7 @@ class AddFingerprintLogic extends BaseGetXController {
|
||||
token: getTokenList,
|
||||
);
|
||||
}else if (deviceConnectionState == DeviceConnectionState.disconnected){
|
||||
// Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
|
||||
Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开");
|
||||
Get.close(2);
|
||||
}
|
||||
});
|
||||
|
||||
@ -288,7 +288,7 @@ class FingerprintListLogic extends BaseGetXController{
|
||||
privateKey:getPrivateKeyList,
|
||||
);
|
||||
}
|
||||
}, isShowLoading: false);
|
||||
});
|
||||
}
|
||||
|
||||
// 删除指纹
|
||||
|
||||
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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){
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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){
|
||||
|
||||
@ -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连接失败重连中
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
});
|
||||
},
|
||||
|
||||
@ -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"];
|
||||
|
||||
@ -101,7 +101,7 @@ class _SaveLockPageState extends State<SaveLockPage> {
|
||||
),
|
||||
onClick: (){
|
||||
// Navigator.pop(context);
|
||||
logic.saveLockAction();
|
||||
logic.addUserConnectBlue();
|
||||
}
|
||||
),
|
||||
],
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -22,6 +22,12 @@ class Toast{
|
||||
);
|
||||
}
|
||||
|
||||
/// 土司提示
|
||||
/// 隐藏
|
||||
static hidden(){
|
||||
ToastPlugins.Fluttertoast.cancel();
|
||||
}
|
||||
|
||||
/// 显示模态弹窗
|
||||
/// context: 上下文
|
||||
/// title:标题
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user