From dcf9502f48ee15c9bf1a50d7e19f6c4093dfd8f6 Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Fri, 5 Jan 2024 14:48:13 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E6=96=B0=E5=A2=9E=E7=9B=91=E8=A7=86?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E8=BF=9E=E6=8E=A5=E5=8D=81=E7=A7=92=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E5=90=8E=E5=8A=A8=E7=94=BB=E6=9A=82=E5=81=9C=20?= =?UTF-8?q?=E5=B9=B6=E5=8F=AF=E5=86=8D=E6=AC=A1=E7=82=B9=E5=87=BB=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=202=EF=BC=8C=E4=BF=AE=E5=A4=8D1000885--1000904?= =?UTF-8?q?=E5=85=B119=E4=B8=AA=E5=85=B3=E4=BA=8E=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E7=B1=BB=E5=9E=8B=E6=9C=AA=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=80=A0=E6=88=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../realTimePicture/realTimePicture_page.dart | 7 +++- .../passwordKeyManage_tabbar.dart | 17 ++++++--- .../passwordKey_perpetual_logic.dart | 36 ++++++++++++------- .../passwordKey_perpetual_page.dart | 16 ++++----- .../passwordKey_perpetual_state.dart | 2 +- star_lock/lib/tools/eventBusEventManage.dart | 6 ++++ 6 files changed, 57 insertions(+), 27 deletions(-) diff --git a/star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_page.dart b/star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_page.dart index 0b503d2c..189fe46c 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_page.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_page.dart @@ -39,6 +39,11 @@ class _RealTimePicturePageState extends State } }); + // 延迟10秒后自动暂停动画 + Future.delayed(const Duration(seconds: 10), () { + state.animationController.stop(); + }); + logic.udpMonitorAction(); } @@ -307,7 +312,7 @@ class _RealTimePicturePageState extends State ), ), onTap: () { - print('点击重新连接'); + state.animationController.forward(); }, ), ); diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyManage/passwordKeyManage_tabbar.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyManage/passwordKeyManage_tabbar.dart index a9cd295e..279a038d 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyManage/passwordKeyManage_tabbar.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyManage/passwordKeyManage_tabbar.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:star_lock/tools/eventBusEventManage.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/CustomUnderlineTabIndicator.dart'; @@ -13,9 +14,7 @@ class PasswordKeyManageTabbarPage extends StatefulWidget { final LockListInfoItemEntity keyInfo; PasswordKeyManageTabbarPage( - {Key? key, - required this.initialIndex, - required this.keyInfo}) + {Key? key, required this.initialIndex, required this.keyInfo}) : super(key: key); @override State createState() => @@ -44,6 +43,16 @@ class _PasswordKeyManageTabbarPageState vsync: this, length: _itemTabs.length, initialIndex: widget.initialIndex); + _tabController.addListener(handleTabIndex); + } + + int handleTabIndex() { + // 获取当前选定的标签索引 + int currentIndex = _tabController.index; + // 根据索引可以得知用户点击了哪个 item + print("User clicked on item at index $currentIndex"); + eventBus.fire(GetPasswordTypeUpdateIndex(currentIndex)); + return currentIndex; } @override @@ -102,7 +111,7 @@ class _PasswordKeyManageTabbarPageState controller: _tabController, children: _itemTabs .map((ItemView item) => PasswordKeyPerpetualPage( - type: item.type, + type: _tabController.index.toString(), getKeyInfo: widget.keyInfo, )) .toList(), diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart index 4fc142eb..3c5a71d8 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart @@ -4,6 +4,7 @@ import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart'; import 'package:star_lock/network/api_repository.dart'; +import 'package:star_lock/tools/eventBusEventManage.dart'; import 'package:star_lock/tools/toast.dart'; import '../../../../blue/blue_manage.dart'; @@ -18,6 +19,15 @@ import '../../../../tools/storage.dart'; class PasswordKeyPerpetualLogic extends BaseGetXController { final PasswordKeyPerpetualState state = PasswordKeyPerpetualState(); + /// 收到点击密码类型更新 + StreamSubscription? getPasswordTypeUpdateIndexEvent; + void getPasswordTypeUpdateIndexAction() { + getPasswordTypeUpdateIndexEvent = + eventBus.on().listen((event) { + state.widgetType.value = event.passwordType; + }); + } + /** 单次 1 只能在开始时间后6小时内使用一次 永久 2 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 @@ -39,20 +49,20 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { String getFailureDateTime = '0'; String getEffectiveDateTime = '0'; String lockId = state.keyInfo.value.lockId.toString(); - int passwordType = int.parse(state.widgetType.value); - String getKeyType = passwordType.toString(); - if (passwordType == 0) { + print('得到的state.widgetType.value为:${state.widgetType.value}'); + String getKeyType = state.widgetType.value.toString(); + if (state.widgetType.value == 0) { //永久 getKeyType = '2'; - } else if (passwordType == 1) { + } else if (state.widgetType.value == 1) { //限时 getKeyType = '3'; - } else if (passwordType == 2) { + } else if (state.widgetType.value == 2) { //单次 getKeyType = '1'; - } else if (passwordType == 3) { + } else if (state.widgetType.value == 3) { //自定义 - } else if (passwordType == 4) { + } else if (state.widgetType.value == 4) { //循环 if (state.loopModeStr.value == '周末') { getKeyType = '5'; @@ -75,15 +85,15 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { } else if (state.loopModeStr.value == '星期日') { getKeyType = '14'; } - } else if (passwordType == 5) { + } else if (state.widgetType.value == 5) { //清空码 getKeyType = '4'; } print('得到的类型为getKeyType$getKeyType'); - if (state.widgetType.value != '0' && - state.widgetType.value != '2' && - state.widgetType.value != '5') { + if (state.widgetType.value != 0 && + state.widgetType.value != 2 && + state.widgetType.value != 5) { getFailureDateTime = state.failureDateTime.value.millisecondsSinceEpoch.toString(); getEffectiveDateTime = @@ -223,7 +233,8 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { // 设置自定义密码 Future senderCustomPasswords() async { - BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState state) async { + BlueManage().bludSendData(BlueManage().connectDeviceName, + (DeviceConnectionState state) async { if (state == DeviceConnectionState.connected) { var publicKey = await Storage.getStringList(saveBluePublicKey); List publicKeyDataList = changeStringListToIntList(publicKey!); @@ -257,6 +268,7 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { super.onReady(); _initReplySubscription(); + getPasswordTypeUpdateIndexAction(); } @override diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart index 3c8f66b9..ebae5be7 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart @@ -5,6 +5,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/app_settings/app_colors.dart'; +import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyManage/passwordKeyManage_tabbar.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart'; import 'package:star_lock/tools/pickers/pickers.dart'; import 'package:star_lock/tools/pickers/style/default_style.dart'; @@ -54,8 +55,6 @@ class _PasswordKeyPerpetualPageState extends State { @override Widget build(BuildContext context) { - state.widgetType.value = widget.type; - return SingleChildScrollView( child: Obx(() => indexChangeWidget()), ); @@ -65,7 +64,7 @@ class _PasswordKeyPerpetualPageState extends State { if (state.isSendSuccess.value == true) { return sendElectronicKeySucceed(); } else { - switch (int.parse(widget.type)) { + switch (state.widgetType.value) { case 0: { // 永久 @@ -186,7 +185,7 @@ class _PasswordKeyPerpetualPageState extends State { action: () { Pickers.showDatePicker(context, mode: DateMode.YMDH, onConfirm: (p) { - if (int.parse(widget.type) == 3) { + if (state.widgetType.value == 3) { // 自定义 state.effectiveDateTime.value = DateTime.parse( '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); @@ -216,7 +215,7 @@ class _PasswordKeyPerpetualPageState extends State { action: () { Pickers.showDatePicker(context, mode: DateMode.YMDH, onConfirm: (p) { - if (int.parse(widget.type) == 3) { + if (state.widgetType.value == 3) { // 自定义 state.failureDateTime.value = DateTime.parse( '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); @@ -400,7 +399,6 @@ class _PasswordKeyPerpetualPageState extends State { onClick: () async { var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); if (isDemoMode == false) { - int getWidgetNumber = int.parse(widget.type); DateTime startDateTime = DateTime( state.effectiveDateTime.value.year, state.effectiveDateTime.value.month, @@ -413,7 +411,7 @@ class _PasswordKeyPerpetualPageState extends State { state.failureDateTime.value.hour); //自定义密码 - if (getWidgetNumber == 3) { + if (state.widgetType.value == 3) { logic.getStartDate(state.effectiveDateTime.value); if (state.nameController.text.isEmpty) { Toast.show(msg: '请输入姓名'); @@ -440,7 +438,7 @@ class _PasswordKeyPerpetualPageState extends State { } //限时 - if (getWidgetNumber == 1) { + if (state.widgetType.value == 1) { if (!startDateTime.isBefore(endDateTime) || startDateTime.isAtSameMomentAs(endDateTime)) { Toast.show(msg: '失效时间需大于生效时间'); @@ -448,7 +446,7 @@ class _PasswordKeyPerpetualPageState extends State { } } //循环密码 - if (getWidgetNumber == 4) { + if (state.widgetType.value == 4) { if (!startDateTime.isBefore(endDateTime) || startDateTime.isAtSameMomentAs(endDateTime)) { Toast.show(msg: '结束时间需大于当前时间'); diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart index b598460c..a5f20071 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart @@ -43,6 +43,6 @@ class PasswordKeyPerpetualState { var loopEndHours = DateTime.now().hour.obs; var loopModeStr = '周末'.obs; //循环模式 - final widgetType = ''.obs; + final widgetType = 0.obs; final keyInfo = LockListInfoItemEntity().obs; } diff --git a/star_lock/lib/tools/eventBusEventManage.dart b/star_lock/lib/tools/eventBusEventManage.dart index eb2a6e51..6e60b3fc 100644 --- a/star_lock/lib/tools/eventBusEventManage.dart +++ b/star_lock/lib/tools/eventBusEventManage.dart @@ -67,3 +67,9 @@ class GetFirstFrameGoPush { bool isFirstFrame; GetFirstFrameGoPush(this.isFirstFrame); } + +/// 获取到实时点击的密码类型更新typeIndex +class GetPasswordTypeUpdateIndex { + int passwordType; + GetPasswordTypeUpdateIndex(this.passwordType); +}