From 264bab98ae0495da2e49d2858a7b7af914c88ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Fri, 5 Jan 2024 13:56:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=93=9D=E7=89=99=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=BC=80=E9=94=81=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star_lock/lib/blue/blue_manage.dart | 2 +- .../lcokSet/lockSet/lockSet_logic.dart | 12 +- .../lockDetail/lockDetail_logic.dart | 231 +++++++++++++----- .../lockDetail/lockDetail_page.dart | 27 +- .../lockDetail/lockDetail_state.dart | 5 +- star_lock/lib/tools/baseGetXController.dart | 19 +- star_lock/pubspec.yaml | 2 +- 7 files changed, 211 insertions(+), 87 deletions(-) diff --git a/star_lock/lib/blue/blue_manage.dart b/star_lock/lib/blue/blue_manage.dart index dc75543b..51f51c9b 100644 --- a/star_lock/lib/blue/blue_manage.dart +++ b/star_lock/lib/blue/blue_manage.dart @@ -90,7 +90,7 @@ class BlueManage { }); } - /// 调用连接 + /// 调用发送数据 Future bludSendData(String deviceName, ConnectStateCallBack stateCallBack) async { if(deviceConnectionState != DeviceConnectionState.connected){ _connect(deviceName, (state){ diff --git a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart index 6ec52434..331f80be 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart @@ -257,7 +257,9 @@ class LockSetLogic extends BaseGetXController { // 删除用户 Future deletUserAction() async { showEasyLoading(); - showBlueConnetctToastTimer(); + showBlueConnetctToastTimer((){ + + }); BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { cancelBlueConnetctToastTimer(); if (connectionState == DeviceConnectionState.connected) { @@ -293,7 +295,9 @@ class LockSetLogic extends BaseGetXController { // 恢复出厂设置 Future factoryDataResetAction() async { showEasyLoading(); - showBlueConnetctToastTimer(); + showBlueConnetctToastTimer((){ + + }); BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { cancelBlueConnetctToastTimer(); if (connectionState == DeviceConnectionState.connected) { @@ -351,7 +355,9 @@ class LockSetLogic extends BaseGetXController { // 设置支持功能(带参数) Future sendBurglarAlarm(int type) async { showEasyLoading(); - showBlueConnetctToastTimer(); + showBlueConnetctToastTimer((){ + + }); BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { cancelBlueConnetctToastTimer(); if (connectionState == DeviceConnectionState.connected) { diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index e62cb715..ce95ae7c 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -4,12 +4,16 @@ 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:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:intl/intl.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/blue/io_protocol/io_editUser.dart'; import 'package:star_lock/blue/io_protocol/io_getLockStatu.dart'; import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/tools/toast.dart'; +import '../../../app_settings/app_colors.dart'; import '../../../blue/blue_manage.dart'; import '../../../blue/io_protocol/io_addUser.dart'; import '../../../blue/io_protocol/io_getStarLockStatusInfo.dart'; @@ -72,16 +76,17 @@ class LockDetailLogic extends BaseGetXController { case 0x00: //成功 print("${reply.commandType}数据解析成功"); + _showFullScreenOverlay(Get.context!); // 电量 int power = reply.data[7]; state.electricQuantity.value = power; + cancelBlueConnetctToastTimer(); getLockRecordLastUploadDataTime(); state.openLockBtnState.value = 0; - state.animationController.reset(); - state.animationController.forward(); - // state.animationController.isCompleted; + // state.animationController.reset(); + // state.animationController.forward(); break; case 0x06: //无权限 @@ -343,15 +348,66 @@ class LockDetailLogic extends BaseGetXController { } } + // 添加用户(普通用户接收电子钥匙) + Future addUserConnectBlue() async { + showBlueConnetctToastTimer(() { + state.openLockBtnState.value = 0; + // state.animationController.reset(); + // state.animationController.forward(); + }); + + BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async { + if (deviceConnectionState == DeviceConnectionState.connected) { + // 私钥 + var privateKey = await Storage.getStringList(saveBluePrivateKey); + List getPrivateKeyList = changeStringListToIntList(privateKey!); + + var publicKey = await Storage.getStringList(saveBluePublicKey); + List publicKeyDataList = changeStringListToIntList(publicKey!); + + var token = await Storage.getStringList(saveBlueToken); + List getTokenList = [0, 0, 0, 0]; + if (token != null) { + getTokenList = changeStringListToIntList(token); + } + print("BlueManage().connectDeviceName:${BlueManage().connectDeviceName} authUserID:${state.senderUserId.toString()} keyID:${state.keyInfos.value.keyId.toString()} userID:${await Storage.getUid()}"); + IoSenderManage.senderAddUser( + lockID: BlueManage().connectDeviceName, + authUserID: state.senderUserId.toString(), + keyID: state.keyInfos.value.keyId.toString(), + userID: await Storage.getUid(), + openMode: 1, + keyType: 0, + startDate: DateTime.now().millisecondsSinceEpoch, + expireDate: 0x11223344, + role: 0, + password: "123456", + needAuthor: 1, + publicKey: publicKeyDataList, + privateKey: getPrivateKeyList, + token: getTokenList); + }else if (deviceConnectionState == DeviceConnectionState.disconnected){ + cancelBlueConnetctToastTimer(); + if(state.ifCurrentScreen.value == true){ + showBlueConnetctToast(); + } + + state.openLockBtnState.value = 0; + // state.animationController.reset(); + // state.animationController.forward(); + } + }); + } + // 点击开门事件 Future openDoorAction() async { - showBlueConnetctToastTimer(); + showBlueConnetctToastTimer(() { + state.openLockBtnState.value = 0; + // state.animationController.reset(); + // state.animationController.forward(); + }); BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async { - cancelBlueConnetctToastTimer(); if (deviceConnectionState == DeviceConnectionState.connected){ - state.connectState.value = 1; - state.openLockBtnState.value = 0; - var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -374,14 +430,14 @@ class LockDetailLogic extends BaseGetXController { privateKey: getPrivateKeyList, ); }else if (deviceConnectionState == DeviceConnectionState.disconnected){ - // if(state.lockState.value != 2){ - // // 2的状态是从已经连接上了 然后没有进行任何操作 锁板主动断开了 所以只需要改变开锁按钮状态不需要弹出toast + cancelBlueConnetctToastTimer(); + if(state.ifCurrentScreen.value == true){ showBlueConnetctToast(); - // } - state.connectState.value = 0; + } + state.openLockBtnState.value = 0; - state.animationController.reset(); - state.animationController.forward(); + // state.animationController.reset(); + // state.animationController.forward(); } }); } @@ -445,7 +501,6 @@ class LockDetailLogic extends BaseGetXController { // }, isShowLoading: false); // } - // 查询事件记录(时间查询) Future senderReferEventRecordTime(int time) async { BlueManage().bludSendData(BlueManage().connectDeviceName, @@ -475,54 +530,13 @@ class LockDetailLogic extends BaseGetXController { }); } - // 添加用户(普通用户接收电子钥匙) - Future addUserConnectBlue() async { - // 进来之后首先连接 - BlueManage().bludSendData(BlueManage().connectDeviceName, - (DeviceConnectionState deviceConnectionState) async { - if (deviceConnectionState == DeviceConnectionState.connected) { - // 私钥 - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = changeStringListToIntList(privateKey!); - - var publicKey = await Storage.getStringList(saveBluePublicKey); - List publicKeyDataList = changeStringListToIntList(publicKey!); - - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = [0, 0, 0, 0]; - if (token != null) { - getTokenList = changeStringListToIntList(token); - } - print( - "BlueManage().connectDeviceName:${BlueManage().connectDeviceName} authUserID:${state.senderUserId.toString()} keyID:${state.keyInfos.value.keyId.toString()} userID:${await Storage.getUid()}"); - IoSenderManage.senderAddUser( - lockID: BlueManage().connectDeviceName, - authUserID: state.senderUserId.toString(), - keyID: state.keyInfos.value.keyId.toString(), - userID: await Storage.getUid(), - openMode: 1, - keyType: 0, - startDate: DateTime.now().millisecondsSinceEpoch, - expireDate: 0x11223344, - role: 0, - password: "123456", - needAuthor: 1, - publicKey: publicKeyDataList, - privateKey: getPrivateKeyList, - token: getTokenList); - } - }); - } - - // 点击开锁 + // startOpenLock() { - // if(state.lockState.value == 4){ - // // 当状态为4的时候,代表是已经连接过一次了,但是连接失败了,所以要重新连接 - // state.lockState.value = 3; - // }else{ - // 其他代表是第一次连接 - state.openLockBtnState.value = 1; - // } + if(state.openLockBtnState.value == 1){ + return; + } + state.iSClosedUnlockSuccessfulPopup.value = false; + state.openLockBtnState.value = 1; state.animationController.forward(); if (state.lockUserNo == 0) { @@ -609,9 +623,7 @@ class LockDetailLogic extends BaseGetXController { _lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent; void _initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction() { // 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus - _lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent = eventBus - .on() - .listen((event) { + _lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent = eventBus.on().listen((event) { if (event.type == 0) { // 0考勤 state.isAttendance.value = event.setResult; @@ -624,6 +636,90 @@ class LockDetailLogic extends BaseGetXController { }); } + late StreamSubscription>_scanListDiscoveredDeviceSubscription; + void _scanListDiscoveredDeviceSubscriptionAction() { + _scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on>().listen((List list) { + final knownDeviceIndex = list.indexWhere((d) => d.name == state.keyInfos.value.bluetooth!.bluetoothDeviceName!); + if (knownDeviceIndex >= 0) { + // 存在的时候赋值 + state.currentDeviceUUid.value = (list[knownDeviceIndex].serviceUuids.isNotEmpty ? list[knownDeviceIndex].serviceUuids[0] : "").toString(); + } + }); + } + + //开锁成功弹出的小界面 + void _showFullScreenOverlay(BuildContext context) { + Future.delayed(const Duration(seconds: 3), () { + if(state.iSClosedUnlockSuccessfulPopup.value == true){ + return; + } + state.iSClosedUnlockSuccessfulPopup.value = true; + Get.back(); + }); + showModalBottomSheet( + context: context, + isScrollControlled: true, + backgroundColor: Colors.transparent, + builder: (BuildContext context) { + return GestureDetector( + onTap: () { + if(state.iSClosedUnlockSuccessfulPopup.value == true){ + return; + } + state.iSClosedUnlockSuccessfulPopup.value = true; + Get.back(); + }, + child: Container( + height: MediaQuery.of(context).size.height, + width: MediaQuery.of(context).size.width, + color: Colors.black.withOpacity(0.2), + child: _unlockSuccessWidget(), + ), + ); + }, + ); + } + + Widget _unlockSuccessWidget() { + return Stack( + alignment: Alignment.center, + children: [ + Image.asset( + 'images/main/unlocked_bg.png', + width: 358.w, + height: 348.h, + ), + Positioned( + top: ScreenUtil().screenHeight / 2, + child: Column( + children: [ + Text( + state.keyInfos.value.lockAlias!, + style: TextStyle( + color: AppColors.placeholderTextColor, fontSize: 24.sp), + ), + SizedBox( + height: 10.h, + ), + Text( + getCurrentFormattedTime(), + style: TextStyle( + color: AppColors.darkGrayTextColor, fontSize: 24.sp), + ) + ], + )) + ], + ); + } + + String getCurrentFormattedTime() { + // 获取当前时间 + DateTime now = DateTime.now(); + // 格式化日期和时间 + String formattedTime = DateFormat('MM/dd HH:mm').format(now); + return formattedTime; + } + @override void onReady() { // TODO: implement onReady @@ -632,6 +728,10 @@ class LockDetailLogic extends BaseGetXController { _initReplySubscription(); _initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction(); + _scanListDiscoveredDeviceSubscriptionAction(); + Future.delayed(const Duration(seconds: 1)).then((value) { + + }); } @override @@ -652,5 +752,6 @@ class LockDetailLogic extends BaseGetXController { _replySubscription.cancel(); _lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent!.cancel(); + _scanListDiscoveredDeviceSubscription.cancel(); } } diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart index 3c46b66c..46528b51 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart @@ -121,7 +121,8 @@ class _LockDetailPageState extends State with TickerProviderStat child: Obx(() => Stack( children: [ Image.asset( - state.connectState.value == 0 ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png', + // state.connectState.value == 0 ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png', + 'images/main/icon_main_openLockBtn_center.png', width: 330.w, height: 330.w, ), @@ -136,7 +137,7 @@ class _LockDetailPageState extends State with TickerProviderStat ], )), onTap: () { - Get.log("点击开锁"); + // Get.log("点击开锁"); logic.startOpenLock(); }, onLongPressStart: (details) { @@ -504,14 +505,14 @@ class _LockDetailPageState extends State with TickerProviderStat height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, color: Colors.black.withOpacity(0.5), - child: unlockSuccessWidget(), + child: _unlockSuccessWidget(), ), ); }, ); } - Widget unlockSuccessWidget() { + Widget _unlockSuccessWidget() { return Stack( alignment: Alignment.center, children: [ @@ -546,10 +547,8 @@ class _LockDetailPageState extends State with TickerProviderStat String getCurrentFormattedTime() { // 获取当前时间 DateTime now = DateTime.now(); - // 格式化日期和时间 String formattedTime = DateFormat('MM/dd HH:mm').format(now); - return formattedTime; } @@ -559,15 +558,18 @@ class _LockDetailPageState extends State with TickerProviderStat super.didChangeDependencies(); /// 路由订阅 - // AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); + AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); } @override void dispose() { // TODO: implement dispose /// 取消路由订阅 + print("LockDetailPage===dispose"); AppRouteObserver().routeObserver.unsubscribe(this); - state.animationController.dispose(); + // state.animationController.reset(); + // state.animationController.forward(); + // state.animationController.dispose(); super.dispose(); BlueManage().disconnect(BlueManage().connectDeviceMacAddress); } @@ -577,6 +579,7 @@ class _LockDetailPageState extends State with TickerProviderStat void didPush() { super.didPush(); print("LockDetailPage===didPush"); + state.ifCurrentScreen.value = true; } /// 返回上一个界面 当前界面即将消失 @@ -584,13 +587,18 @@ class _LockDetailPageState extends State with TickerProviderStat void didPop() { super.didPop(); print("LockDetailPage===didPop"); + state.ifCurrentScreen.value = false; logic.cancelBlueConnetctToastTimer(); + state.animationController.reset(); + state.animationController.forward(); + state.animationController.dispose(); } /// 从下级返回 当前界面即将出现 @override void didPopNext() { super.didPopNext(); + state.ifCurrentScreen.value = true; print("LockDetailPage===didPopNext"); } @@ -599,7 +607,10 @@ class _LockDetailPageState extends State with TickerProviderStat void didPushNext() { super.didPushNext(); print("LockDetailPage===didPushNext"); + state.ifCurrentScreen.value = false; logic.cancelBlueConnetctToastTimer(); + state.animationController.reset(); + state.animationController.forward(); } } diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_state.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_state.dart index 21073d3a..d4efd193 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_state.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_state.dart @@ -26,9 +26,12 @@ class LockDetailState { var currentDeviceUUid = "".obs;// 当前设备的uuid + var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + var iSClosedUnlockSuccessfulPopup = false.obs; // 是否关闭了开锁成功弹窗 + //过渡动画控制器 late AnimationController animationController; // var lockState = 0.obs;// 0未连接普通状态 1连接开锁中(展示动画) 2已连接开锁成功 3检测可用性 4连接失败 5连接失败重连中 var openLockBtnState = 0.obs;// 0普通状态(未转动) 1连接中(转动状态) - var connectState = 0.obs;// 0未连接 1连接 + // var connectState = 0.obs;// 0未连接 1连接 } \ No newline at end of file diff --git a/star_lock/lib/tools/baseGetXController.dart b/star_lock/lib/tools/baseGetXController.dart index 736fb17e..e8dd1444 100644 --- a/star_lock/lib/tools/baseGetXController.dart +++ b/star_lock/lib/tools/baseGetXController.dart @@ -45,10 +45,6 @@ class BaseGetXController extends GetxController{ Get.log('onClose -----> $runtimeType'); } - // operationFailedCallBack(e){ - // showOperationFailed(); - // } - Future delay({Duration? duration,Function? something}) => Future.delayed(duration ?? 500. milliseconds,something as FutureOr Function()?); void showEasyLoading() => EasyLoading.show(); @@ -57,12 +53,17 @@ class BaseGetXController extends GetxController{ Timer? _timer; // CancelableOperation? _operation; - void showBlueConnetctToastTimer() { - if(_timer != null && _timer!.isActive){ + void showBlueConnetctToastTimer(Function? something) { + if(_timer != null){ _timer!.cancel(); + _timer = null; } _timer = Timer.periodic(15.seconds, (timer) { + cancelBlueConnetctToastTimer(); showBlueConnetctToast(); + if(something != null) { + something(); + } }); // _operation = CancelableOperation.fromFuture( // Future.delayed(const Duration(seconds: 15), () { @@ -74,7 +75,10 @@ class BaseGetXController extends GetxController{ void cancelBlueConnetctToastTimer() { Get.log('cancelBlueConnetctToastTimer'); - if(_timer != null && _timer!.isActive) _timer!.cancel(); + if(_timer != null){ + _timer!.cancel(); + _timer = null; + } // _operation?.cancel(); } @@ -136,7 +140,6 @@ class BaseGetXController extends GetxController{ } - ///Extension_Int extension Extension_Int on int { bool get codeIsSuccessful => this == 0; diff --git a/star_lock/pubspec.yaml b/star_lock/pubspec.yaml index cbbfa761..55ce37d5 100644 --- a/star_lock/pubspec.yaml +++ b/star_lock/pubspec.yaml @@ -128,7 +128,7 @@ dependencies: # ffmpeg_kit_flutter: 5.1.0-LTS fast_gbk: ^1.0.0 flutter_pcm_sound: ^1.1.0 - intl: ^0.18.1 + intl: ^0.18.0 # flutter_audio_capture: <1.1.5 flutter_voice_processor: ^1.1.0