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); +}