完善添加锁流程,添加长按闭锁功能

This commit is contained in:
魏少阳 2024-01-08 17:58:19 +08:00
parent b8278db9ef
commit 8c2fdf6d8a
19 changed files with 194 additions and 102 deletions

View File

@ -61,7 +61,14 @@ class BlueManage {
_sendStreamSubscription ??= EventBusManager().eventBus!.on<EventSendModel>().listen((EventSendModel model) {
if (model.sendChannel == DataChannel.ble) {
// managerAppWriteData(model.data);
writeCharacteristicWithResponse(model.data);
_flutterReactiveBle!.statusStream.listen((status) {
if (status == BleStatus.ready) {
//
writeCharacteristicWithResponse(model.data);
}else{
Get.log("写入数据 蓝牙未开启,不能进行蓝牙操作");
}
});
}
});
}
@ -69,43 +76,57 @@ class BlueManage {
///
void startScan({List<Uuid>? idList}) {
// List<Service>? list = _flutterReactiveBle!.getDiscoveredServices("deviceId").then((value));
scanDevices.clear();
_scanSubscription = _flutterReactiveBle!.scanForDevices(withServices:[]).listen((device) {
//
if (device.name.isEmpty) {
return;
_flutterReactiveBle!.statusStream.listen((status) {
if (status == BleStatus.ready) {
//
scanDevices.clear();
_scanSubscription = _flutterReactiveBle!.scanForDevices(withServices:[]).listen((device) {
//
if (device.name.isEmpty) {
return;
}
print("startScanDevice:$device");
if (((device.serviceUuids.isNotEmpty ? device.serviceUuids[0] : "").toString().contains("758824")) && (device.rssi >= -100)) {
// id相同的元素
final knownDeviceIndex = scanDevices.indexWhere((d) => d.id == device.id);
// -1
if (knownDeviceIndex >= 0) {
scanDevices[knownDeviceIndex] = device;
} else {
scanDevices.add(device);
}
EventBusManager().eventBusFir(scanDevices);
}
}, onError: (Object e) {
print('Device scan fails with error: $e');
});
}else{
Get.log("开始扫描 蓝牙未开启,不能进行蓝牙操作");
}
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> bludSendData(String deviceName, ConnectStateCallBack stateCallBack, {bool isAddEquipment = false}) async {
if(deviceConnectionState != DeviceConnectionState.connected){
if(isAddEquipment == false){
startScan();
}
_flutterReactiveBle!.statusStream.listen((status) {
if (status == BleStatus.ready) {
//
if(deviceConnectionState != DeviceConnectionState.connected){
if(isAddEquipment == false){
startScan();
}
_connect(deviceName, (state){
stateCallBack(deviceConnectionState!);
});
}else{
stateCallBack(deviceConnectionState!);
}
_connect(deviceName, (state){
stateCallBack(deviceConnectionState!);
});
}else{
stateCallBack(deviceConnectionState!);
}
}else{
Get.log("调用发送数据 蓝牙未开启,不能进行蓝牙操作");
}
});
}
///

View File

@ -501,18 +501,18 @@ class LockSetLogic extends BaseGetXController {
if (entity.errorCode!.codeIsSuccessful) {
Get.back();
if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){
//
//
if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) {
//
factoryDataResetAction();
} else {
//
deletUserAction();
}
return;
}
// if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){
// //
// //
// if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) {
// //
// factoryDataResetAction();
// } else {
// //
// deletUserAction();
// }
// return;
// }
if (state.currentDeviceUUid.value.isNotEmpty) {
//
@ -539,6 +539,7 @@ class LockSetLogic extends BaseGetXController {
}else{
//
if (state.currentDeviceUUid.isNotEmpty) {
BlueManage().stopScan();
//
if(state.deletWaitScanTimer != null){
state.deletWaitScanTimer!.cancel();
@ -546,7 +547,6 @@ class LockSetLogic extends BaseGetXController {
if(state.deletWaitScanCompleter != null){
state.deletWaitScanCompleter!.complete();
}
BlueManage().stopScan();
dismissEasyLoading();
deletLockLogic();

View File

@ -306,7 +306,7 @@ class LockDetailLogic extends BaseGetXController {
// updateLockUserNo();
if (state.isOpenLockNeedOnline.value == 0) {
openDoorAction();
openDoorAction(1);
} else {
getLockNetToken();
}
@ -407,7 +407,7 @@ class LockDetailLogic extends BaseGetXController {
}
//
Future<void> openDoorAction() async {
Future<void> openDoorAction(int openMode) async {
showBlueConnetctToastTimer(action:() {
state.openLockBtnState.value = 0;
// state.animationController.reset();
@ -428,7 +428,7 @@ class LockDetailLogic extends BaseGetXController {
IoSenderManage.senderOpenLock(
keyID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: 1,
openMode: openMode,
openTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
onlineToken: state.lockNetToken,
token: getTokenList,
@ -542,6 +542,7 @@ class LockDetailLogic extends BaseGetXController {
if(state.openLockBtnState.value == 1){
return;
}
state.iSOpenLock.value = true;
state.iSClosedUnlockSuccessfulPopup.value = false;
state.openLockBtnState.value = 1;
state.animationController.forward();
@ -552,7 +553,7 @@ class LockDetailLogic extends BaseGetXController {
} else {
if (state.isOpenLockNeedOnline.value == 0) {
//
openDoorAction();
openDoorAction(1);
} else {
//
getLockNetToken();
@ -560,6 +561,23 @@ class LockDetailLogic extends BaseGetXController {
}
}
startUnLock() {
if(state.openLockBtnState.value == 1){
return;
}
state.iSOpenLock.value = false;
state.iSClosedUnlockSuccessfulPopup.value = false;
state.openLockBtnState.value = 1;
state.animationController.forward();
if (state.lockUserNo == 0) {
// lockUserNo为0
addUserConnectBlue();
} else {
openDoorAction(32);
}
}
longPressCloseDoor(){
}
@ -571,7 +589,7 @@ class LockDetailLogic extends BaseGetXController {
if (entity.errorCode!.codeIsSuccessful) {
state.lockNetToken = entity.data!.token!;
print("state.lockNetToken:${state.lockNetToken}");
openDoorAction();
openDoorAction(1);
}
}
@ -582,7 +600,7 @@ class LockDetailLogic extends BaseGetXController {
lockUserNo: state.lockUserNo.toString());
if (entity.errorCode!.codeIsSuccessful) {
if (state.isOpenLockNeedOnline.value == 0) {
openDoorAction();
openDoorAction(1);
} else {
getLockNetToken();
}

View File

@ -76,32 +76,37 @@ class _LockDetailPageState extends State<LockDetailPage>
@override
Widget build(BuildContext context) {
return Stack(children: [
Container(
width: 1.sw,
height: 1.sh - ScreenUtil().statusBarHeight * 2,
color: Colors.white,
child: Column(
children: [
topWidget(),
Expanded(child: Obx(() => bottomWidget())),
],
),
),
Obx(() => Visibility(
visible: state.iSClosedUnlockSuccessfulPopup.value,
child: GestureDetector(
onTap: () {
state.iSClosedUnlockSuccessfulPopup.value = false;
},
child: Container(
width: 1.sw,
height: 1.sh,
color: Colors.black.withOpacity(0.3),
child: _unlockSuccessWidget()),
return ListView(
children: [
Stack(children: [
Container(
width: 1.sw,
height: 1.sh - ScreenUtil().statusBarHeight * 2,
color: Colors.white,
child: Column(
children: [
topWidget(),
Expanded(child: Obx(() => bottomWidget())),
],
),
))
]);
),
Obx(() => Visibility(
visible: state.iSClosedUnlockSuccessfulPopup.value,
// visible: true,
child: GestureDetector(
onTap: () {
state.iSClosedUnlockSuccessfulPopup.value = false;
},
child: Container(
width: 1.sw,
height: 1.sh - ScreenUtil().statusBarHeight * 2,
color: Colors.black.withOpacity(0.3),
child: _unlockSuccessWidget()),
),
))
]),
],
);
}
Widget topWidget() {
@ -170,8 +175,8 @@ class _LockDetailPageState extends State<LockDetailPage>
logic.startOpenLock();
},
onLongPressStart: (details) {
Get.log("长按");
// logic.startConnect();
Get.log("长按");
logic.startUnLock();
},
)),
],
@ -556,12 +561,12 @@ class _LockDetailPageState extends State<LockDetailPage>
alignment: Alignment.center,
children: [
Image.asset(
'images/main/unlocked_bg.png',
state.iSOpenLock.value == true ? 'images/main/unlocked_bg.png' : 'images/main/locked_bg.png',
width: 358.w,
height: 348.h,
),
Positioned(
top: 1.sh / 2 - 70.h,
top: (1.sh - ScreenUtil().statusBarHeight * 2)/ 2,
child: Column(
children: [
Text(

View File

@ -30,6 +30,7 @@ class LockDetailState {
var ifCurrentScreen = true.obs; // ,
var iSClosedUnlockSuccessfulPopup = false.obs; //
var iSOpenLock = true.obs; //
Timer? closedUnlockSuccessfulTimer;
//

View File

@ -5,6 +5,7 @@ import 'package:get/get.dart';
import 'package:star_lock/talk/call/callTalk.dart';
import '../../../../app_settings/app_colors.dart';
import '../../../../login/seletCountryRegion/common/index.dart';
import '../../../../talk/udp/udp_manage.dart';
import '../../../../talk/udp/udp_senderManage.dart';
import '../../../../tools/showTFView.dart';
@ -157,8 +158,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
Widget bottomBottomBtnWidget() {
return Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
//
Obx(() => bottomBtnItemWidget(
getAnswerBtnImg(), getAnswerBtnName(), Colors.white, () async {
Obx(() => bottomBtnItemWidget(getAnswerBtnImg(), getAnswerBtnName(), Colors.white, () async {
//
await logic.getPermissionStatus().then((value) async {
if (!value) {
@ -274,8 +274,17 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
return;
}
List<int> numbers = state.passwordTF.text.split('').map((char) => int.parse(char)).toList();
// List<int> numbers = state.passwordTF.text.split('').map((char) => int.parse(char)).toList();
//
// lockID
List<int> numbers = [];
List<int> lockIDData = utf8.encode(state.passwordTF.text);
numbers.addAll(lockIDData);
// topBytes = getFixedLengthList(lockIDData, 20 - lockIDData.length);
for (int i = 0; i < 6 - lockIDData.length; i++) {
numbers.add(0);
}
print("numbersnumbersnumbers:$numbers");
logic.udpOpenDoorAction(numbers);
},
cancelClick: () {

View File

@ -116,15 +116,17 @@ class LockMainLogic extends BaseGetXController {
if (connectResult == ConnectivityResult.mobile) {
// _netType = "4G";
print("4G 4G 4G 4G 4G");
state.networkConnectionStatus.value = 1;
// print("4G 4G 4G 4G 4G");
} else if (connectResult == ConnectivityResult.wifi) {
// _netType = "wifi";
print("wifi wifi wifi wifi wifi");
state.networkConnectionStatus.value = 1;
// print("wifi wifi wifi wifi wifi");
} else {
// _netType = "未连接";
print("未连接 未连接 未连接 未连接 未连接");
state.networkConnectionStatus.value = 0;
// print("未连接 未连接 未连接 未连接 未连接");
}
}
///
@ -137,6 +139,11 @@ class LockMainLogic extends BaseGetXController {
connectListener() async {
Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
print("设置网络切换监听:$result");
if(state.networkConnectionStatus.value == 0 && result != ConnectivityResult.none){
//
state.networkConnectionStatus.value = 1;
getStarLockInfo();
}
});
}
@ -160,9 +167,9 @@ class LockMainLogic extends BaseGetXController {
// getLockInfo();
//
// connectListener();
connectListener();
//
// getConnectType();
getConnectType();
getStarLockInfo();
}

View File

@ -10,5 +10,8 @@ class LockMainState {
var dataLength = 100.obs;
var lockListInfoEntity = LockListInfoEntity().obs;
// 0 1
var networkConnectionStatus = 0.obs;
// late Timer timer;
}

View File

@ -38,7 +38,7 @@ class _AbountPageState extends State<AbountPage> {
),
SizedBox(height: 20.h),
Text(
"星锁 1.0.0.03(preRelease-20240108)",
"星锁 1.0.0.04(preRelease-20240108-1)",
style: TextStyle(fontSize: 24.sp, color: AppColors.blackColor),
),
SizedBox(

View File

@ -131,6 +131,7 @@ class _AddLockSeletCountryPageState extends State<AddLockSeletCountryPage> {
"featureValue": state.featureValue,
"featureSettingValue": state.featureSettingValue,
"featureSettingParams": state.featureSettingParams,
"isFromMap": 0,
});
},
),
@ -152,6 +153,7 @@ class _AddLockSeletCountryPageState extends State<AddLockSeletCountryPage> {
"featureValue": state.featureValue,
"featureSettingValue": state.featureSettingValue,
"featureSettingParams": state.featureSettingParams,
"isFromMap": 0,
});
// Navigator.pushNamed(context, Routers.saveLockPage);
},

View File

@ -50,6 +50,10 @@ class LockAddressGaoDeLogic extends BaseGetXController{
// ..startLocation();
// }
void pushAddAction(){
}
@override
void onReady() {
// TODO: implement onReady

View File

@ -67,14 +67,18 @@ class _LockAddressGaoDePageState extends State<LockAddressGaoDePage> with RouteA
final status = await Permission.location.request();
print("Permission.location.request()=status:$status");
permissionStatus = status;
if(Platform.isIOS){
_setLocationOption();
requestIOSLocation();
}
switch (status) {
case PermissionStatus.denied:
print("拒绝");
break;
case PermissionStatus.granted:
if(Platform.isIOS){
_setLocationOption();
requestIOSLocation();
// _setLocationOption();
// requestIOSLocation();
}else{
requestAndroidLocation();
location.startLocation();
@ -83,6 +87,12 @@ class _LockAddressGaoDePageState extends State<LockAddressGaoDePage> with RouteA
case PermissionStatus.limited:
print("限制");
break;
case PermissionStatus.permanentlyDenied:
print("永久的否认");
break;
case PermissionStatus.provisional:
print("临时");
break;
default:
print("其他状态");
// requestLocation();
@ -264,6 +274,7 @@ class _LockAddressGaoDePageState extends State<LockAddressGaoDePage> with RouteA
"featureValue": state.featureValue,
"featureSettingValue": state.featureSettingValue,
"featureSettingParams": state.featureSettingParams,
"isFromMap": 1,
});
// Navigator.pushNamed(context, Routers.saveLockPage);
},

View File

@ -373,13 +373,16 @@ class NearbyLockLogic extends BaseGetXController {
_initReplySubscription();
_scanListDiscoveredDeviceSubscriptionAction();
state.ifCurrentScreen.value = true;
startScanBlueList();
}
@override
void onInit() {
// TODO: implement onInit
super.onInit();
print("NearbyLockLogic onInit()");
super.onInit();
}
@override

View File

@ -145,14 +145,17 @@ class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
@override
void didPush() {
super.didPush();
state.ifCurrentScreen.value = true;
logic.startScanBlueList();
Get.log("NearbyLockLogic didPush()");
// state.ifCurrentScreen.value = true;
// logic.startScanBlueList();
}
///
@override
void didPop() {
super.didPop();
Get.log("NearbyLockLogic didPop()");
state.ifCurrentScreen.value = false;
logic.cancelBlueConnetctToastTimer();
@ -163,6 +166,7 @@ class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
@override
void didPopNext() {
super.didPopNext();
Get.log("NearbyLockLogic didPopNext()");
state.ifCurrentScreen.value = true;
logic.startScanBlueList();
@ -172,6 +176,7 @@ class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
@override
void didPushNext() {
super.didPushNext();
Get.log("NearbyLockLogic didPushNext()");
state.ifCurrentScreen.value = false;
logic.cancelBlueConnetctToastTimer();

View File

@ -155,7 +155,7 @@ class SaveLockLogic extends BaseGetXController {
showBlueConnetctToast();
}
}
});
}, isAddEquipment: true);
}
@ -204,7 +204,7 @@ class SaveLockLogic extends BaseGetXController {
if (entity.errorCode!.codeIsSuccessful) {
BlueManage().disconnect(BlueManage().connectDeviceMacAddress);
eventBus.fire(RefreshLockListInfoDataEvent());
Get.close(5);
Get.close(state.isFromMap == 1 ? 5 : 6);
// Future.delayed(const Duration(milliseconds: 200), () {
// Get.offAllNamed(Routers.starLockMain);
// });
@ -231,6 +231,7 @@ class SaveLockLogic extends BaseGetXController {
void onClose() {
// TODO: implement onClose
_replySubscription.cancel();
BlueManage().stopScan();
super.onClose();
}
}

View File

@ -16,6 +16,7 @@ class SaveLockState {
var featureValue = '';
var featureSettingValue = '';
var featureSettingParams = [];
var isFromMap = 0; // 0: 1:
var ifCurrentScreen = true.obs; // ,
var saveBtnIsUsable = true.obs; //
@ -31,6 +32,7 @@ class SaveLockState {
featureValue = map["featureValue"];
featureSettingValue = map["featureSettingValue"];
featureSettingParams = map["featureSettingParams"];
isFromMap = map["isFromMap"];
}
void onClose() {

View File

@ -1,6 +1,6 @@
abstract class Api {
// static String baseAddress = "https://pre.lock.star-lock.cn:8093"; //
static String baseAddress = "http://192.168.56.101:8099"; //
static String baseAddress = "https://pre.lock.star-lock.cn:8093"; //
// static String baseAddress = "http://192.168.56.101:8099"; //
// static String baseAddress = "http://192.168.1.15:8022"; //
final String baseUrl = "$baseAddress/api";

View File

@ -71,7 +71,7 @@ class CallTalk {
// 63
int getIframeIndex =
bb[POS_iframe_index] + bb[POS_iframe_index + 1] * 256;
print('获取帧序号 getIframeIndex$getIframeIndex');
// print('获取帧序号 getIframeIndex$getIframeIndex');
// 65
// int alen = bb[POS_alen] & 0xff;
@ -84,10 +84,10 @@ class CallTalk {
// 71
int getBagIndex = bb[POS_bag_index] & 0xff;
print('当前包号 getBagIndex$getBagIndex');
// print('当前包号 getBagIndex$getBagIndex');
// 69
int getBagNum = bb[POS_bag_num] & 0xff;
print('总包数 getBagNum$getBagNum');
// print('总包数 getBagNum$getBagNum');
// 73
int blen = bb[POS_blen] + bb[POS_blen + 1] * 256;
// print('数据长度 blen$blen');

View File

@ -63,7 +63,7 @@ class BaseGetXController extends GetxController{
action();
}
cancelBlueConnetctToastTimer();
if(isShowBlueConnetctToast == false){
if(isShowBlueConnetctToast == true){
showBlueConnetctToast();
}
});