fix: 增加日志

This commit is contained in:
liyi 2025-10-27 09:27:37 +08:00
parent 41aea1d1bf
commit f6e900aaad
7 changed files with 142 additions and 222 deletions

View File

@ -1,4 +1,3 @@
import 'dart:async'; import 'dart:async';
import 'package:star_lock/blue/entity/lock_user_no_list_entity.dart'; import 'package:star_lock/blue/entity/lock_user_no_list_entity.dart';
@ -22,10 +21,10 @@ import 'io_tool/manager_event_bus.dart';
import 'sender_data.dart'; import 'sender_data.dart';
class SenderBeforeDataManage { class SenderBeforeDataManage {
factory SenderBeforeDataManage() => shareManager()!; factory SenderBeforeDataManage() => shareManager()!;
SenderBeforeDataManage._init(); SenderBeforeDataManage._init();
static SenderBeforeDataManage? _manager; static SenderBeforeDataManage? _manager;
static SenderBeforeDataManage? shareManager() { static SenderBeforeDataManage? shareManager() {
@ -42,6 +41,7 @@ class SenderBeforeDataManage {
// //
StreamSubscription<Reply>? _replySubscription; StreamSubscription<Reply>? _replySubscription;
// //
bool isBeforeAddUser = true; bool isBeforeAddUser = true;
@ -146,10 +146,8 @@ class SenderBeforeDataManage {
// //
Future<List<int>> getCleanUpUsers({List<int>? tokenList}) async { Future<List<int>> getCleanUpUsers({List<int>? tokenList}) async {
final LockUserNoListEntity entity = await ApiRepository.to final LockUserNoListEntity entity = await ApiRepository.to.getLockUserNoList(lockId: CommonDataManage().currentKeyInfo.lockId!);
.getLockUserNoList(lockId: CommonDataManage().currentKeyInfo.lockId!); if (!entity.errorCode!.codeIsSuccessful || (entity.data?.userNos ?? <int>[]).isEmpty) {
if (!entity.errorCode!.codeIsSuccessful ||
(entity.data?.userNos ?? <int>[]).isEmpty) {
throw Exception('ApiRepository.to.getLockUserNoList 访问失败'); throw Exception('ApiRepository.to.getLockUserNoList 访问失败');
} }
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey); final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
@ -208,7 +206,8 @@ class SenderBeforeDataManage {
endTime = DateTime.fromMillisecondsSinceEpoch(currentKeyInfo.endDate!); endTime = DateTime.fromMillisecondsSinceEpoch(currentKeyInfo.endDate!);
startDateTime = DateTool().dateToTimestamp(DateTool().dateToYMDString(currentKeyInfo.startDate!.toString()), 1) ~/ 1000; startDateTime = DateTool().dateToTimestamp(DateTool().dateToYMDString(currentKeyInfo.startDate!.toString()), 1) ~/ 1000;
endDateTime = (DateTool().dateToTimestamp(DateTool().dateToYMDString(currentKeyInfo.endDate!.toString()), 1) + CommonDataManage().dayLatestTime) ~/ 1000; endDateTime =
(DateTool().dateToTimestamp(DateTool().dateToYMDString(currentKeyInfo.endDate!.toString()), 1) + CommonDataManage().dayLatestTime) ~/ 1000;
} else if (currentKeyInfo.keyType == XSConstantMacro.keyTypeOnce) { } else if (currentKeyInfo.keyType == XSConstantMacro.keyTypeOnce) {
// //
useCountLimit = 1; useCountLimit = 1;
@ -217,7 +216,7 @@ class SenderBeforeDataManage {
// AppLog.log("startTime.hour:${startTime!.hour} startTime.minute:${startTime!.minute} endTime.hour:${endTime!.hour} endTime.minute:${endTime!.minute}}"); // AppLog.log("startTime.hour:${startTime!.hour} startTime.minute:${startTime!.minute} endTime.hour:${endTime!.hour} endTime.minute:${endTime!.minute}}");
final AddUserCommand addUserData = AddUserCommand( final AddUserCommand addUserData = AddUserCommand(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
authUserID: currentKeyInfo.senderUserId!.toString(), authUserID: currentKeyInfo.senderUserId?.toString() ?? '1',
keyID: currentKeyInfo.keyId.toString(), keyID: currentKeyInfo.keyId.toString(),
userID: await Storage.getUid(), userID: await Storage.getUid(),
openMode: 1, openMode: 1,
@ -226,10 +225,7 @@ class SenderBeforeDataManage {
expireDate: endDateTime, expireDate: endDateTime,
useCountLimit: useCountLimit, useCountLimit: useCountLimit,
isRound: isRound ? 1 : 0, isRound: isRound ? 1 : 0,
weekRound: isRound weekRound: isRound ? DateTool().accordingTheCycleIntoTheCorrespondingNumber(currentKeyInfo.weekDays!) : 0,
? DateTool().accordingTheCycleIntoTheCorrespondingNumber(
currentKeyInfo.weekDays!)
: 0,
startHour: isRound ? startTime!.hour : 0, startHour: isRound ? startTime!.hour : 0,
startMin: isRound ? startTime!.minute : 0, startMin: isRound ? startTime!.minute : 0,
endHour: isRound ? endTime!.hour : 0, endHour: isRound ? endTime!.hour : 0,
@ -271,8 +267,7 @@ class SenderBeforeDataManage {
// NO // NO
Future<void> _updateLockUserNo(List<int> dataList) async { Future<void> _updateLockUserNo(List<int> dataList) async {
final LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo( final LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo(
keyId: CommonDataManage().currentKeyInfo.keyId.toString(), keyId: CommonDataManage().currentKeyInfo.keyId.toString(), lockUserNo: CommonDataManage().currentKeyInfo.lockUserNo.toString());
lockUserNo: CommonDataManage().currentKeyInfo.lockUserNo.toString());
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
eventBus.fire(RefreshLockListInfoDataEvent()); eventBus.fire(RefreshLockListInfoDataEvent());
eventBus.fire(LockAddUserSucceedEvent(<int>[0], 0)); eventBus.fire(LockAddUserSucceedEvent(<int>[0], 0));
@ -281,9 +276,8 @@ class SenderBeforeDataManage {
// InitUserNo // InitUserNo
Future<void> _updateLockInitUserNo() async { Future<void> _updateLockInitUserNo() async {
final LockNetTokenEntity entity = await ApiRepository.to.updateLockInitUserNo( final LockNetTokenEntity entity = await ApiRepository.to
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0, .updateLockInitUserNo(lockId: CommonDataManage().currentKeyInfo.lockId ?? 0, initUserNo: CommonDataManage().currentKeyInfo.initUserNo ?? 0);
initUserNo: CommonDataManage().currentKeyInfo.initUserNo ?? 0);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
eventBus.fire(RefreshLockListInfoDataEvent()); eventBus.fire(RefreshLockListInfoDataEvent());
eventBus.fire(LockInitUserNoEvent()); eventBus.fire(LockInitUserNoEvent());

View File

@ -88,17 +88,18 @@ class LockListLogic extends BaseGetXController {
break; break;
case 0x06: case 0x06:
// //
final List<String>? token = await Storage.getStringList(saveBlueToken); final List<int> tokenData = reply.data.sublist(2, 6);
final List<int> getTokenList = changeStringListToIntList(token!); final List<String> saveStrList = changeIntListToStringList(tokenData);
Storage.setStringList(saveBlueToken, saveStrList);
IoSenderManage.senderFactoryDataReset( IoSenderManage.senderFactoryDataReset(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(), userID: await Storage.getUid(),
keyID: '1', keyID: '1',
needAuthor: 1, needAuthor: 1,
publicKey: state.lockListInfoItemEntity.value.bluetooth!.publicKey!.cast<int>(), publicKey: state.publicKey,
privateKey: state.lockListInfoItemEntity.value.bluetooth!.privateKey!.cast<int>(), privateKey: state.privateKey,
token: getTokenList); token: tokenData,
);
break; break;
case 0x07: case 0x07:
// //
@ -172,14 +173,14 @@ class LockListLogic extends BaseGetXController {
} }
/// ///
void deleyLockLogicOfRoles() { void deleyLockLogicOfRoles(LockListInfoItemEntity keyInfo) {
if (state.lockListInfoItemEntity.value.isLockOwner == 1) { if (state.lockListInfoItemEntity.value.isLockOwner == 1) {
// //
showTipView.showIosTipWithContentDialog('删除锁后,所有信息都会一起删除,确定删除锁吗?'.tr, () { showTipView.showIosTipWithContentDialog('删除锁后,所有信息都会一起删除,确定删除锁吗?'.tr, () {
// //
AppLog.log('调用了删除锁'); AppLog.log('调用了删除锁');
showTipView.resetGetController(); showTipView.resetGetController();
showTipView.showTFViewAlertDialog(state.passwordTF, '请输入登录密码'.tr, '请输入登录密码'.tr, checkLoginPassword); showTipView.showTFViewAlertDialog(state.passwordTF, '请输入登录密码'.tr, '请输入登录密码'.tr, () => checkLoginPassword(keyInfo));
}); });
} else if (state.lockListInfoItemEntity.value.keyRight == 1) { } else if (state.lockListInfoItemEntity.value.keyRight == 1) {
// //
@ -195,13 +196,13 @@ class LockListLogic extends BaseGetXController {
} }
// //
Future<void> checkLoginPassword() async { Future<void> checkLoginPassword(LockListInfoItemEntity keyInfo) async {
final LockListInfoEntity entity = await ApiRepository.to.checkLoginPassword( final LockListInfoEntity entity = await ApiRepository.to.checkLoginPassword(
password: state.passwordTF.text, password: state.passwordTF.text,
); );
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
Get.back(); Get.back();
factoryDataResetAction(); factoryDataResetAction(keyInfo);
} }
} }
@ -233,7 +234,7 @@ class LockListLogic extends BaseGetXController {
} }
// //
Future<void> factoryDataResetAction() async { Future<void> factoryDataResetAction(LockListInfoItemEntity keyInfo) async {
showEasyLoading(); showEasyLoading();
showBlueConnetctToastTimer( showBlueConnetctToastTimer(
isShowBlueConnetctToast: false, isShowBlueConnetctToast: false,
@ -241,15 +242,13 @@ class LockListLogic extends BaseGetXController {
dismissEasyLoading(); dismissEasyLoading();
showDeletAlertTipDialog(); showDeletAlertTipDialog();
}); });
BlueManage().blueSendData(state.lockListInfoItemEntity.value.lockName!, (BluetoothConnectionState connectionState) BlueManage().blueSendData(state.lockListInfoItemEntity.value.lockName!, (BluetoothConnectionState connectionState) async {
async {
if (connectionState == BluetoothConnectionState.connected) { if (connectionState == BluetoothConnectionState.connected) {
final List<int> publicKeyData = state.lockListInfoItemEntity.value.bluetooth!.publicKey!.cast<int>(); final List<int> publicKeyData = state.lockListInfoItemEntity.value.bluetooth!.publicKey!.cast<int>();
final List<String> saveStrList = changeIntListToStringList(publicKeyData); final List<String> saveStrList = changeIntListToStringList(publicKeyData);
await Storage.setStringList(saveBluePublicKey, saveStrList); await Storage.setStringList(saveBluePublicKey, saveStrList);
// //
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> privateKeyData = state.lockListInfoItemEntity.value.bluetooth!.privateKey!.cast<int>(); final List<int> privateKeyData = state.lockListInfoItemEntity.value.bluetooth!.privateKey!.cast<int>();
final List<String> savePrivateKeyList = changeIntListToStringList(privateKeyData); final List<String> savePrivateKeyList = changeIntListToStringList(privateKeyData);
await Storage.setStringList(saveBluePrivateKey, savePrivateKeyList); await Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
@ -262,15 +261,18 @@ class LockListLogic extends BaseGetXController {
final List<String> saveTokenList = changeIntListToStringList(<int>[0, 0, 0, 0]); final List<String> saveTokenList = changeIntListToStringList(<int>[0, 0, 0, 0]);
await Storage.setStringList(saveBlueToken, saveTokenList); await Storage.setStringList(saveBlueToken, saveTokenList);
IoSenderManage.senderFactoryDataReset( IoSenderManage.senderFactoryDataReset(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(), userID: await Storage.getUid(),
keyID: '1', keyID: '1',
needAuthor: 1, needAuthor: 1,
publicKey: publicKeyData, publicKey: keyInfo.bluetooth?.publicKey ?? [],
privateKey: privateKeyData, privateKey: keyInfo.bluetooth?.privateKey ?? [],
token: <int>[0, 0, 0, 0]); token: <int>[0, 0, 0, 0]);
state.publicKey.value = keyInfo.bluetooth?.publicKey ?? [];
state.privateKey.value = keyInfo.bluetooth?.privateKey ?? [];
state.publicKey.refresh();
state.privateKey.refresh();
} else if (connectionState == BluetoothConnectionState.disconnected) { } else if (connectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/main/lockMian/lockList/lockList_state.dart'; import 'package:star_lock/main/lockMian/lockList/lockList_state.dart';
import '../../../appRouters.dart'; import '../../../appRouters.dart';
@ -14,8 +15,7 @@ import 'lockListGroup_view.dart';
import 'lockList_logic.dart'; import 'lockList_logic.dart';
class LockListPage extends StatefulWidget { class LockListPage extends StatefulWidget {
const LockListPage({required this.lockListInfoGroupEntity, Key? key}) const LockListPage({required this.lockListInfoGroupEntity, Key? key}) : super(key: key);
: super(key: key);
final LockListInfoGroupEntity lockListInfoGroupEntity; final LockListInfoGroupEntity lockListInfoGroupEntity;
@override @override
@ -30,16 +30,15 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
void initState() { void initState() {
super.initState(); super.initState();
logic = Get.put(LockListLogic(widget.lockListInfoGroupEntity)); logic = Get.put(LockListLogic(widget.lockListInfoGroupEntity));
state = Get state = Get.find<LockListLogic>().state;
.find<LockListLogic>()
.state;
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Obx(() => Scaffold( return Obx(
() => Scaffold(
body: ListView.separated( body: ListView.separated(
itemCount: logic.groupDataListFiltered.length, itemCount: logic.groupDataList.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
final GroupList itemData = logic.groupDataListFiltered[index]; final GroupList itemData = logic.groupDataListFiltered[index];
return _buildLockExpandedList(context, index, itemData, key: ValueKey(itemData.groupId)); return _buildLockExpandedList(context, index, itemData, key: ValueKey(itemData.groupId));
@ -51,20 +50,21 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
height: 1, height: 1,
color: AppColors.greyLineColor, color: AppColors.greyLineColor,
); );
}), },
)); ),
),
);
} }
// //
Widget _buildLockExpandedList(BuildContext context, int index, Widget _buildLockExpandedList(BuildContext context, int index, GroupList itemData, {Key? key}) {
GroupList itemData, {Key? key}) { final List<LockListInfoItemEntity> lockItemList = itemData.lockList ?? <LockListInfoItemEntity>[];
final List<LockListInfoItemEntity> lockItemList =
itemData.lockList ?? <LockListInfoItemEntity>[];
return LockListGroupView( return LockListGroupView(
key: key, key: key,
onTap: () { onTap: () {
// //
if (itemData.isChecked) {} else {} if (itemData.isChecked) {
} else {}
setState(() {}); setState(() {});
}, },
typeImgList: const <dynamic>[], typeImgList: const <dynamic>[],
@ -91,9 +91,12 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
children: <Widget>[ children: <Widget>[
SlidableAction( SlidableAction(
onPressed: (BuildContext context) { onPressed: (BuildContext context) {
state.publicKey.value = keyInfo.bluetooth?.publicKey ?? [];
state.privateKey.value = keyInfo.bluetooth?.privateKey ?? [];
state.lockListInfoItemEntity.value = keyInfo; state.lockListInfoItemEntity.value = keyInfo;
state.lockListInfoItemEntity.refresh(); state.lockListInfoItemEntity.refresh();
logic.deleyLockLogicOfRoles(); AppLog.log('msg=================:${state.lockListInfoItemEntity.value}');
logic.deleyLockLogicOfRoles(keyInfo);
}, },
backgroundColor: Colors.red, backgroundColor: Colors.red,
foregroundColor: Colors.white, foregroundColor: Colors.white,
@ -103,10 +106,8 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
], ],
), ),
child: lockInfoListItem(keyInfo, isLast, () { child: lockInfoListItem(keyInfo, isLast, () {
if ((keyInfo.keyType == XSConstantMacro.keyTypeTime || if ((keyInfo.keyType == XSConstantMacro.keyTypeTime || keyInfo.keyType == XSConstantMacro.keyTypeLoop) &&
keyInfo.keyType == XSConstantMacro.keyTypeLoop) && (keyInfo.keyStatus == XSConstantMacro.keyStatusWaitIneffective)) {
(keyInfo.keyStatus ==
XSConstantMacro.keyStatusWaitIneffective)) {
logic.showToast('您的钥匙未生效'.tr); logic.showToast('您的钥匙未生效'.tr);
return; return;
} }
@ -117,14 +118,12 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
logic.showToast('您的钥匙已冻结'.tr); logic.showToast('您的钥匙已冻结'.tr);
return; return;
} }
if ((keyInfo.keyType == XSConstantMacro.keyTypeTime || if ((keyInfo.keyType == XSConstantMacro.keyTypeTime || keyInfo.keyType == XSConstantMacro.keyTypeLoop) &&
keyInfo.keyType == XSConstantMacro.keyTypeLoop) &&
(keyInfo.keyStatus == XSConstantMacro.keyStatusExpired)) { (keyInfo.keyStatus == XSConstantMacro.keyStatusExpired)) {
logic.showToast('您的钥匙已过期'.tr); logic.showToast('您的钥匙已过期'.tr);
return; return;
} }
Get.toNamed(Routers.lockDetailMainPage, Get.toNamed(Routers.lockDetailMainPage, arguments: <String, Object>{
arguments: <String, Object>{
// "lockMainEntity": widget.lockMainEntity, // "lockMainEntity": widget.lockMainEntity,
'keyInfo': keyInfo, 'keyInfo': keyInfo,
'isOnlyOneData': false, 'isOnlyOneData': false,
@ -135,26 +134,18 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
); );
} }
Widget lockInfoListItem(LockListInfoItemEntity keyInfo, bool isLast, Widget lockInfoListItem(LockListInfoItemEntity keyInfo, bool isLast, Function() action) {
Function() action) {
return GestureDetector( return GestureDetector(
onTap: action, onTap: action,
child: Container( child: Container(
// height: 122.h, // height: 122.h,
margin: isLast margin: isLast ? EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w, bottom: 20.w) : EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w),
? EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w, bottom: 20.w)
: EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: (((keyInfo.keyType == XSConstantMacro.keyTypeTime || color: (((keyInfo.keyType == XSConstantMacro.keyTypeTime || keyInfo.keyType == XSConstantMacro.keyTypeLoop) &&
keyInfo.keyType == XSConstantMacro.keyTypeLoop) && (keyInfo.keyStatus == XSConstantMacro.keyStatusWaitIneffective ||
(keyInfo.keyStatus == keyInfo.keyStatus == XSConstantMacro.keyStatusFrozen ||
XSConstantMacro.keyStatusWaitIneffective || keyInfo.keyStatus == XSConstantMacro.keyStatusExpired)) ||
keyInfo.keyStatus == (keyInfo.keyType == XSConstantMacro.keyTypeLong && keyInfo.keyStatus == XSConstantMacro.keyStatusFrozen))
XSConstantMacro.keyStatusFrozen ||
keyInfo.keyStatus ==
XSConstantMacro.keyStatusExpired)) ||
(keyInfo.keyType == XSConstantMacro.keyTypeLong &&
keyInfo.keyStatus == XSConstantMacro.keyStatusFrozen))
? AppColors.greyBackgroundColor ? AppColors.greyBackgroundColor
: Colors.white, : Colors.white,
borderRadius: BorderRadius.circular(20.w), borderRadius: BorderRadius.circular(20.w),
@ -178,9 +169,7 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
style: TextStyle( style: TextStyle(
fontSize: 24.sp, fontSize: 24.sp,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: keyInfo.passageMode == 1 color: keyInfo.passageMode == 1 ? AppColors.openPassageModeColor : AppColors.darkGrayTextColor),
? AppColors.openPassageModeColor
: AppColors.darkGrayTextColor),
), ),
], ],
), ),
@ -194,8 +183,7 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
SizedBox(width: 2.w), SizedBox(width: 2.w),
Text( Text(
'${keyInfo.electricQuantity!}%', '${keyInfo.electricQuantity!}%',
style: TextStyle( style: TextStyle(fontSize: 18.sp, color: AppColors.darkGrayTextColor),
fontSize: 18.sp, color: AppColors.darkGrayTextColor),
), ),
SizedBox(width: 30.w), SizedBox(width: 30.w),
], ],
@ -212,10 +200,7 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
borderRadius: BorderRadius.circular(5.w), borderRadius: BorderRadius.circular(5.w),
color: AppColors.openPassageModeColor, color: AppColors.openPassageModeColor,
), ),
child: Text('常开模式开启'.tr, child: Text('常开模式开启'.tr, style: TextStyle(fontSize: 18.sp, color: AppColors.appBarIconColor)),
style: TextStyle(
fontSize: 18.sp,
color: AppColors.appBarIconColor)),
), ),
], ],
)), )),
@ -227,8 +212,7 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
SizedBox(width: 30.w), SizedBox(width: 30.w),
Text( Text(
'远程开锁'.tr, '远程开锁'.tr,
style: TextStyle( style: TextStyle(fontSize: 18.sp, color: AppColors.darkGrayTextColor),
fontSize: 18.sp, color: AppColors.darkGrayTextColor),
), ),
], ],
)), )),
@ -242,13 +226,9 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
padding: EdgeInsets.only(right: 5.w, left: 5.w), padding: EdgeInsets.only(right: 5.w, left: 5.w),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.w), borderRadius: BorderRadius.circular(5.w),
color: color: DateTool().compareTimeIsOvertime(keyInfo.endDate!) ? AppColors.listTimeYellowColor : AppColors.mainColor,
DateTool().compareTimeIsOvertime(keyInfo.endDate!)
? AppColors.listTimeYellowColor
: AppColors.mainColor,
), ),
child: Text(logic.getKeyEffective(keyInfo), child: Text(logic.getKeyEffective(keyInfo), style: TextStyle(fontSize: 18.sp, color: Colors.white)
style: TextStyle(fontSize: 18.sp, color: Colors.white)
// child: Text(logic.compareTimeIsOvertime(keyInfo.endDate!) ? "已过期" : "${logic.compareTimeGetDaysFromNow(keyInfo.endDate!)}", style: TextStyle(fontSize: 18.sp, color: Colors.white) // child: Text(logic.compareTimeIsOvertime(keyInfo.endDate!) ? "已过期" : "${logic.compareTimeGetDaysFromNow(keyInfo.endDate!)}", style: TextStyle(fontSize: 18.sp, color: Colors.white)
), ),
), ),
@ -259,13 +239,8 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
children: <Widget>[ children: <Widget>[
SizedBox(width: 30.w), SizedBox(width: 30.w),
Text( Text(
"${logic.getUseKeyTypeStr(keyInfo.startDate, keyInfo.endDate, "${logic.getUseKeyTypeStr(keyInfo.startDate, keyInfo.endDate, keyInfo.keyType)}/${keyInfo.isLockOwner == 1 ? '超级管理员'.tr : (keyInfo.keyRight == 1 ? "授权管理员".tr : "普通用户".tr)}",
keyInfo.keyType)}/${keyInfo.isLockOwner == 1 style: TextStyle(fontSize: 18.sp, color: AppColors.darkGrayTextColor),
? '超级管理员'.tr
: (keyInfo.keyRight == 1 ? "授权管理员".tr : "普通用户"
.tr)}",
style: TextStyle(
fontSize: 18.sp, color: AppColors.darkGrayTextColor),
), ),
], ],
), ),
@ -287,13 +262,10 @@ class _LockListPageState extends State<LockListPage> with RouteAware {
@override @override
void dispose() { void dispose() {
Get.delete<LockListLogic>(); Get.delete<LockListLogic>();
/// ///
AppRouteObserver().routeObserver.unsubscribe(this); AppRouteObserver().routeObserver.unsubscribe(this);
super super.dispose();
.
dispose
(
);
} }
/// ///

View File

@ -14,5 +14,7 @@ class LockListState{
RxBool ifCurrentScreen = true.obs; // , RxBool ifCurrentScreen = true.obs; // ,
RxBool showSearch = false.obs; // , RxBool showSearch = false.obs; // ,
RxString searchStr = ''.obs; // , RxString searchStr = ''.obs; // ,
RxList<int> publicKey=<int>[].obs;
RxList<int> privateKey=<int>[].obs;
} }

View File

@ -194,7 +194,7 @@ class _LockListXHJPageState extends State<LockListXHJPage> with RouteAware {
onPressed: (BuildContext context) { onPressed: (BuildContext context) {
state.lockListInfoItemEntity.value = keyInfo; state.lockListInfoItemEntity.value = keyInfo;
state.lockListInfoItemEntity.refresh(); state.lockListInfoItemEntity.refresh();
logic.deleyLockLogicOfRoles(); logic.deleyLockLogicOfRoles(keyInfo);
}, },
backgroundColor: Colors.red, backgroundColor: Colors.red,
foregroundColor: Colors.white, foregroundColor: Colors.white,

View File

@ -36,7 +36,7 @@ class UdpTalkDataHandler extends ScpMessageBaseHandle implements ScpMessageHandl
if (scpMessage.Payload != null) { if (scpMessage.Payload != null) {
final TalkData talkData = scpMessage.Payload; final TalkData talkData = scpMessage.Payload;
AppLog.log('收到数据');
_handleTalkData( _handleTalkData(
talkData: talkData, talkData: talkData,
scpMessage: scpMessage, scpMessage: scpMessage,

View File

@ -104,10 +104,8 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
codecType: 'h264', codecType: 'h264',
); );
// textureId // textureId
AppLog.log( AppLog.log('StartChartManage().videoWidth:${StartChartManage().videoWidth}');
'StartChartManage().videoWidth:${StartChartManage().videoWidth}'); AppLog.log('StartChartManage().videoHeight:${StartChartManage().videoHeight}');
AppLog.log(
'StartChartManage().videoHeight:${StartChartManage().videoHeight}');
final textureId = await VideoDecodePlugin.initDecoder(config); final textureId = await VideoDecodePlugin.initDecoder(config);
if (textureId != null) { if (textureId != null) {
Future.microtask(() => state.textureId.value = textureId); Future.microtask(() => state.textureId.value = textureId);
@ -172,15 +170,11 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
ScpMessage scpMessage, ScpMessage scpMessage,
) { ) {
// frameSeq较小时阈值也小 // frameSeq较小时阈值也小
if (!_pendingStreamReset && if (!_pendingStreamReset && _lastFrameSeq != null && frameType == TalkDataH264Frame_FrameTypeE.I && frameSeq < _lastFrameSeq!) {
_lastFrameSeq != null &&
frameType == TalkDataH264Frame_FrameTypeE.I &&
frameSeq < _lastFrameSeq!) {
int dynamicThreshold = _getFrameSeqRolloverThreshold(_lastFrameSeq!); int dynamicThreshold = _getFrameSeqRolloverThreshold(_lastFrameSeq!);
if ((_lastFrameSeq! - frameSeq) > dynamicThreshold) { if ((_lastFrameSeq! - frameSeq) > dynamicThreshold) {
// I帧frameSeq大幅回绕loading并重置所有本地状态 // I帧frameSeq大幅回绕loading并重置所有本地状态
AppLog.log( AppLog.log('检测到新流I帧frameSeq大幅回绕进入loading并重置: frameSeq=$frameSeq, lastFrameSeq=$_lastFrameSeq, 阈值=$dynamicThreshold');
'检测到新流I帧frameSeq大幅回绕进入loading并重置: frameSeq=$frameSeq, lastFrameSeq=$_lastFrameSeq, 阈值=$dynamicThreshold');
Future.microtask(() => state.isLoading.value = true); Future.microtask(() => state.isLoading.value = true);
_pendingStreamReset = true; _pendingStreamReset = true;
// //
@ -197,8 +191,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
// //
} else { } else {
// //
AppLog.log( AppLog.log('检测到I帧乱序未超过回绕阈值$dynamicThreshold),丢弃: frameSeq=$frameSeq, lastFrameSeq=$_lastFrameSeq');
'检测到I帧乱序未超过回绕阈值$dynamicThreshold),丢弃: frameSeq=$frameSeq, lastFrameSeq=$_lastFrameSeq');
return; return;
} }
} }
@ -238,8 +231,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
// P/B帧 // P/B帧
while (state.h264FrameBuffer.length >= state.maxFrameBufferSize) { while (state.h264FrameBuffer.length >= state.maxFrameBufferSize) {
int pbIndex = state.h264FrameBuffer int pbIndex = state.h264FrameBuffer.indexWhere((f) => f['frameType'] == TalkDataH264Frame_FrameTypeE.P);
.indexWhere((f) => f['frameType'] == TalkDataH264Frame_FrameTypeE.P);
if (pbIndex != -1) { if (pbIndex != -1) {
state.h264FrameBuffer.removeAt(pbIndex); state.h264FrameBuffer.removeAt(pbIndex);
} else { } else {
@ -260,8 +252,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
final int intervalMs = (1000 / state.targetFps).round(); final int intervalMs = (1000 / state.targetFps).round();
// //
state.frameProcessTimer = state.frameProcessTimer = Timer.periodic(Duration(milliseconds: intervalMs), (timer) {
Timer.periodic(Duration(milliseconds: intervalMs), (timer) {
_processNextFrameFromBuffer(); _processNextFrameFromBuffer();
}); });
AppLog.log('启动帧处理定时器,目标帧率: ${state.targetFps}fps间隔: ${intervalMs}ms'); AppLog.log('启动帧处理定时器,目标帧率: ${state.targetFps}fps间隔: ${intervalMs}ms');
@ -280,24 +271,18 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
} }
// I帧frameSeq最小的I帧消费 // I帧frameSeq最小的I帧消费
final iFrames = state.h264FrameBuffer final iFrames = state.h264FrameBuffer.where((f) => f['frameType'] == TalkDataH264Frame_FrameTypeE.I).toList();
.where((f) => f['frameType'] == TalkDataH264Frame_FrameTypeE.I) iFrames.sort((a, b) => (a['frameSeq'] as int).compareTo(b['frameSeq'] as int));
.toList();
iFrames
.sort((a, b) => (a['frameSeq'] as int).compareTo(b['frameSeq'] as int));
if (iFrames.isNotEmpty) { if (iFrames.isNotEmpty) {
// I帧I帧frameSeq // I帧I帧frameSeq
final minIFrame = iFrames.first; final minIFrame = iFrames.first;
final minIFrameSeq = minIFrame['frameSeq']; final minIFrameSeq = minIFrame['frameSeq'];
final targetIndex = state.h264FrameBuffer.indexWhere( final targetIndex = state.h264FrameBuffer.indexWhere(
(f) => (f) => f['frameType'] == TalkDataH264Frame_FrameTypeE.I && f['frameSeq'] == minIFrameSeq,
f['frameType'] == TalkDataH264Frame_FrameTypeE.I &&
f['frameSeq'] == minIFrameSeq,
); );
state.isProcessingFrame = true; state.isProcessingFrame = true;
final Map<String, dynamic>? frameMap = final Map<String, dynamic>? frameMap = state.h264FrameBuffer.removeAt(targetIndex);
state.h264FrameBuffer.removeAt(targetIndex);
if (frameMap == null) { if (frameMap == null) {
state.isProcessingFrame = false; state.isProcessingFrame = false;
return; return;
@ -308,11 +293,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
final int? frameSeqI = frameMap['frameSeqI']; final int? frameSeqI = frameMap['frameSeqI'];
final int? pts = frameMap['pts']; final int? pts = frameMap['pts'];
final ScpMessage? scpMessage = frameMap['scpMessage']; final ScpMessage? scpMessage = frameMap['scpMessage'];
if (frameData == null || if (frameData == null || frameType == null || frameSeq == null || frameSeqI == null || pts == null) {
frameType == null ||
frameSeq == null ||
frameSeqI == null ||
pts == null) {
state.isProcessingFrame = false; state.isProcessingFrame = false;
return; return;
} }
@ -321,11 +302,8 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
return; return;
} }
lastDecodedIFrameSeq = minIFrameSeq; lastDecodedIFrameSeq = minIFrameSeq;
// AppLog.log('送入解码器的P帧数据frameSeq:${frameSeq},frameSeqI:${frameSeqI},' AppLog.log('送入解码器的P帧数据frameSeq:${frameSeq},frameSeqI:${frameSeqI},'
// 'frameType:${frameType},messageId:${scpMessage!.MessageId}'); 'frameType:${frameType},messageId:${scpMessage!.MessageId}');
// final spsData = NaluUtils.filterNalusByType(frameData, 7);
// final ppsData = NaluUtils.filterNalusByType(frameData, 8);
// AppLog.log('SPSDATA:${spsData}ppsData:${ppsData}');
await VideoDecodePlugin.sendFrame( await VideoDecodePlugin.sendFrame(
frameData: frameData, frameData: frameData,
frameType: 0, frameType: 0,
@ -340,24 +318,16 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
// I帧时refIFrameSeq等于lastDecodedIFrameSeq的P帧 // I帧时refIFrameSeq等于lastDecodedIFrameSeq的P帧
if (lastDecodedIFrameSeq != null) { if (lastDecodedIFrameSeq != null) {
final validPFrames = state.h264FrameBuffer final validPFrames =
.where((f) => state.h264FrameBuffer.where((f) => f['frameType'] == TalkDataH264Frame_FrameTypeE.P && f['frameSeqI'] == lastDecodedIFrameSeq).toList();
f['frameType'] == TalkDataH264Frame_FrameTypeE.P &&
f['frameSeqI'] == lastDecodedIFrameSeq)
.toList();
if (validPFrames.isNotEmpty) { if (validPFrames.isNotEmpty) {
validPFrames.sort( validPFrames.sort((a, b) => (a['frameSeq'] as int).compareTo(b['frameSeq'] as int));
(a, b) => (a['frameSeq'] as int).compareTo(b['frameSeq'] as int));
final minPFrame = validPFrames.first; final minPFrame = validPFrames.first;
final targetIndex = state.h264FrameBuffer.indexWhere( final targetIndex = state.h264FrameBuffer.indexWhere(
(f) => (f) => f['frameType'] == TalkDataH264Frame_FrameTypeE.P && f['frameSeq'] == minPFrame['frameSeq'] && f['frameSeqI'] == lastDecodedIFrameSeq,
f['frameType'] == TalkDataH264Frame_FrameTypeE.P &&
f['frameSeq'] == minPFrame['frameSeq'] &&
f['frameSeqI'] == lastDecodedIFrameSeq,
); );
state.isProcessingFrame = true; state.isProcessingFrame = true;
final Map<String, dynamic>? frameMap = final Map<String, dynamic>? frameMap = state.h264FrameBuffer.removeAt(targetIndex);
state.h264FrameBuffer.removeAt(targetIndex);
if (frameMap == null) { if (frameMap == null) {
state.isProcessingFrame = false; state.isProcessingFrame = false;
return; return;
@ -368,11 +338,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
final int? frameSeqI = frameMap['frameSeqI']; final int? frameSeqI = frameMap['frameSeqI'];
final int? pts = frameMap['pts']; final int? pts = frameMap['pts'];
final ScpMessage? scpMessage = frameMap['scpMessage']; final ScpMessage? scpMessage = frameMap['scpMessage'];
if (frameData == null || if (frameData == null || frameType == null || frameSeq == null || frameSeqI == null || pts == null) {
frameType == null ||
frameSeq == null ||
frameSeqI == null ||
pts == null) {
state.isProcessingFrame = false; state.isProcessingFrame = false;
return; return;
} }
@ -427,8 +393,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
AppLog.log("==== 启动新的数据流监听 ===="); AppLog.log("==== 启动新的数据流监听 ====");
_isListening = true; _isListening = true;
_streamSubscription = state.talkDataRepository.talkDataStream _streamSubscription = state.talkDataRepository.talkDataStream.listen((TalkDataModel talkDataModel) async {
.listen((TalkDataModel talkDataModel) async {
_processFrame(talkDataModel); _processFrame(talkDataModel);
}); });
} }
@ -437,8 +402,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
void _playAudioFrames() { void _playAudioFrames() {
// //
// //
if (state.audioBuffer.isEmpty || if (state.audioBuffer.isEmpty || state.audioBuffer.length < audioBufferSize) {
state.audioBuffer.length < audioBufferSize) {
return; return;
} }
@ -446,8 +410,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
TalkData? oldestFrame; TalkData? oldestFrame;
int oldestIndex = -1; int oldestIndex = -1;
for (int i = 0; i < state.audioBuffer.length; i++) { for (int i = 0; i < state.audioBuffer.length; i++) {
if (oldestFrame == null || if (oldestFrame == null || state.audioBuffer[i].durationMs < oldestFrame.durationMs) {
state.audioBuffer[i].durationMs < oldestFrame.durationMs) {
oldestFrame = state.audioBuffer[i]; oldestFrame = state.audioBuffer[i];
oldestIndex = i; oldestIndex = i;
} }
@ -477,8 +440,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
break; break;
case TalkStatus.answeredSuccessfully: case TalkStatus.answeredSuccessfully:
state.oneMinuteTimeTimer?.cancel(); // state.oneMinuteTimeTimer?.cancel(); //
state.oneMinuteTimeTimer ??= state.oneMinuteTimeTimer ??= Timer.periodic(const Duration(seconds: 1), (Timer t) {
Timer.periodic(const Duration(seconds: 1), (Timer t) {
if (state.isLoading.isFalse) { if (state.isLoading.isFalse) {
state.oneMinuteTime.value++; state.oneMinuteTime.value++;
} }
@ -493,9 +455,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
/// ///
void _playAudioData(TalkData talkData) async { void _playAudioData(TalkData talkData) async {
if (state.isOpenVoice.value && if (state.isOpenVoice.value && state.isLoading.isFalse && state.isRecordingAudio.value == false) {
state.isLoading.isFalse &&
state.isRecordingAudio.value == false) {
List<int> encodedData = G711Tool.decode(talkData.content, 0); // 0A-law List<int> encodedData = G711Tool.decode(talkData.content, 0); // 0A-law
// PCM PcmArrayInt16 // PCM PcmArrayInt16
final PcmArrayInt16 fromList = PcmArrayInt16.fromList(encodedData); final PcmArrayInt16 fromList = PcmArrayInt16.fromList(encodedData);
@ -670,11 +630,9 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
AppLog.log('截图失败: 未找到当前上下文'); AppLog.log('截图失败: 未找到当前上下文');
return; return;
} }
final RenderRepaintBoundary boundary = state.globalKey.currentContext! final RenderRepaintBoundary boundary = state.globalKey.currentContext!.findRenderObject()! as RenderRepaintBoundary;
.findRenderObject()! as RenderRepaintBoundary;
final ui.Image image = await boundary.toImage(); final ui.Image image = await boundary.toImage();
final ByteData? byteData = final ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
await image.toByteData(format: ui.ImageByteFormat.png);
if (byteData == null) { if (byteData == null) {
AppLog.log('截图失败: 图像数据为空'); AppLog.log('截图失败: 图像数据为空');
@ -702,15 +660,13 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
// //
Future<void> remoteOpenLock() async { Future<void> remoteOpenLock() async {
final LockListInfoItemEntity currentKeyInfo = final LockListInfoItemEntity currentKeyInfo = CommonDataManage().currentKeyInfo;
CommonDataManage().currentKeyInfo;
var lockId = currentKeyInfo.lockId ?? 0; var lockId = currentKeyInfo.lockId ?? 0;
var remoteUnlock = currentKeyInfo.lockSetting?.remoteUnlock ?? 0; var remoteUnlock = currentKeyInfo.lockSetting?.remoteUnlock ?? 0;
final lockPeerId = StartChartManage().lockPeerId; final lockPeerId = StartChartManage().lockPeerId;
final LockListInfoGroupEntity? lockListInfoGroupEntity = final LockListInfoGroupEntity? lockListInfoGroupEntity = await Storage.getLockMainListData();
await Storage.getLockMainListData();
if (lockListInfoGroupEntity != null) { if (lockListInfoGroupEntity != null) {
lockListInfoGroupEntity!.groupList?.forEach((element) { lockListInfoGroupEntity!.groupList?.forEach((element) {
final lockList = element.lockList; final lockList = element.lockList;
@ -728,8 +684,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
}); });
} }
if (remoteUnlock == 1) { if (remoteUnlock == 1) {
final LoginEntity entity = await ApiRepository.to final LoginEntity entity = await ApiRepository.to.remoteOpenLock(lockId: lockId.toString(), timeOut: 60);
.remoteOpenLock(lockId: lockId.toString(), timeOut: 60);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
showToast('已开锁'.tr); showToast('已开锁'.tr);
StartChartManage().lockListPeerId = []; StartChartManage().lockListPeerId = [];
@ -756,8 +711,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
state.startRecordingAudioTime.value = DateTime.now(); state.startRecordingAudioTime.value = DateTime.now();
// //
state.voiceProcessor state.voiceProcessor?.addFrameListeners(<VoiceProcessorFrameListener>[_onFrame]);
?.addFrameListeners(<VoiceProcessorFrameListener>[_onFrame]);
state.voiceProcessor?.addErrorListener(_onError); state.voiceProcessor?.addErrorListener(_onError);
} else { } else {
// state.errorMessage.value = 'Recording permission not granted'; // state.errorMessage.value = 'Recording permission not granted';
@ -777,8 +731,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
state.endRecordingAudioTime.value = DateTime.now(); state.endRecordingAudioTime.value = DateTime.now();
// //
final Duration duration = state.endRecordingAudioTime.value final Duration duration = state.endRecordingAudioTime.value.difference(state.startRecordingAudioTime.value);
.difference(state.startRecordingAudioTime.value);
state.recordingAudioTime.value = duration.inSeconds; state.recordingAudioTime.value = duration.inSeconds;
} on PlatformException catch (ex) { } on PlatformException catch (ex) {
@ -848,10 +801,8 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
_bufferedAudioFrames.addAll(encodedData); _bufferedAudioFrames.addAll(encodedData);
// //
if (_startProcessingAudioTimer == null && if (_startProcessingAudioTimer == null && _bufferedAudioFrames.length > chunkSize) {
_bufferedAudioFrames.length > chunkSize) { _startProcessingAudioTimer = Timer.periodic(Duration(milliseconds: intervalMs), _sendAudioChunk);
_startProcessingAudioTimer =
Timer.periodic(Duration(milliseconds: intervalMs), _sendAudioChunk);
} }
} }
@ -887,8 +838,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
} }
/// ///
StartChartManage().changeTalkExpectDataTypeAndReStartTalkExpectMessageTimer( StartChartManage().changeTalkExpectDataTypeAndReStartTalkExpectMessageTimer(talkExpect: talkExpectReq);
talkExpect: talkExpectReq);
// loadingframeSeq回绕检测 // loadingframeSeq回绕检测
// frameSeq回绕检测标志 // frameSeq回绕检测标志