fix:修复 上传电池后,其他页面的电池没有试试刷新

This commit is contained in:
anfe 2024-06-05 17:36:46 +08:00
parent c53a60a95a
commit 5f190aa587
7 changed files with 111 additions and 61 deletions

View File

@ -522,5 +522,18 @@ class LockDetailLogic extends BaseGetXController {
@override
void onInit() {
super.onInit();
state.LockSetChangeSetRefreshLockDetailWithTypeSubscription = eventBus
.on<LockSetChangeSetRefreshLockDetailWithType>()
.listen((LockSetChangeSetRefreshLockDetailWithType event) {
if (event.type == 4) {
final int electricQuantity =
int.tryParse(event.setResult['electricQuantity']) ?? 0;
state.electricQuantity.value = electricQuantity;
state.keyInfos.value.electricQuantity = electricQuantity;
state.keyInfos.value.electricQuantityDate =
event.setResult['uploadElectricQuantityDate'] ?? 0;
state.keyInfos.refresh();
}
});
}
}

View File

@ -29,15 +29,14 @@ import '../../lockMian/entity/lockListInfo_entity.dart';
import 'lockDetail_logic.dart';
class LockDetailPage extends StatefulWidget {
const LockDetailPage(
{required this.isOnlyOneData,
required this.lockListInfoItemEntity,
Key? key})
: super(key: key);
final bool isOnlyOneData;
final LockListInfoItemEntity lockListInfoItemEntity;
const LockDetailPage(
{Key? key,
required this.isOnlyOneData,
required this.lockListInfoItemEntity})
: super(key: key);
@override
State<LockDetailPage> createState() => _LockDetailPageState();
}
@ -50,7 +49,6 @@ class _LockDetailPageState extends State<LockDetailPage>
@override
void initState() {
// TODO: implement initState
super.initState();
listeningAnimations();
@ -1438,8 +1436,9 @@ class _LockDetailPageState extends State<LockDetailPage>
state.closedUnlockSuccessfulTimer?.cancel();
_lockRefreshLockDetailInfoDataEvent?.cancel();
state.replySubscription.cancel();
state.lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent!
.cancel();
state.lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent
?.cancel();
state.LockSetChangeSetRefreshLockDetailWithTypeSubscription?.cancel();
if (state.animationController != null) {
state.animationController!.dispose();
state.animationController = null;

View File

@ -12,44 +12,45 @@ class LockDetailState {
late StreamSubscription<Reply> replySubscription;
StreamSubscription? lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent;
StreamSubscription? LockSetChangeSetRefreshLockDetailWithTypeSubscription;
String lockNetToken = "0";
String lockNetToken = '0';
int differentialTime = 0;
int lockUserNo = 0;
var senderUserId = 0;
var isOnlyOneData = false;
int senderUserId = 0;
bool isOnlyOneData = false;
var isAttendance = 0.obs; //
var isOpenLockNeedOnline = 0.obs; // APP开锁时是否需联网
var electricQuantity = 0.obs; //
var electricQuantityStandby = 0.obs; //
var isOpenPassageMode = 0.obs; //
var lockAlias = "".obs; //
RxInt isAttendance = 0.obs; //
RxInt isOpenLockNeedOnline = 0.obs; // APP开锁时是否需联网
RxInt electricQuantity = 0.obs; //
RxInt electricQuantityStandby = 0.obs; //
RxInt isOpenPassageMode = 0.obs; //
RxString lockAlias = ''.obs; //
// var currentDeviceUUid = "".obs; // uuid
var ifCurrentScreen = true.obs; // ,
var iSClosedUnlockSuccessfulPopup = false.obs; //
var iSOpenLock = true.obs; //
RxBool ifCurrentScreen = true.obs; // ,
RxBool iSClosedUnlockSuccessfulPopup = false.obs; //
RxBool iSOpenLock = true.obs; //
Timer? closedUnlockSuccessfulTimer;
var bottomBtnisEable = true.obs; //
var openDoorBtnisUneable = true.obs; // 使使,
RxBool bottomBtnisEable = true.obs; //
RxBool openDoorBtnisUneable = true.obs; // 使使,
var openDoorModel = 0;// 线0, 线2 线32 线34
int openDoorModel = 0;// 线0, 线2 线32 线34
//
AnimationController? animationController;
// var lockState = 0.obs;// 0 1() 2 3 4 5
var openLockBtnState = 0.obs; // 0() 1()
RxInt openLockBtnState = 0.obs; // 0() 1()
// var connectState = 0.obs;// 0 1
final PageController pageController = PageController();
var currentPage = 0.obs;
RxInt currentPage = 0.obs;
var operateDate = 0; //
var logCountPage = 10; //
var nextAuthTime = 0.obs; //
int operateDate = 0; //
int logCountPage = 10; //
RxInt nextAuthTime = 0.obs; //
// LockDetailState() {
// Map map = Get.arguments;
// lockCount = map["lockCount"];

View File

@ -20,6 +20,7 @@ class BasicInformationLogic extends BaseGetXController {
//
StreamSubscription? _passCurrentLockInformationEvent;
StreamSubscription? lockSetChangeSetRefreshLockDetailWithTypeSubscription;
void initLoadDataAction(BlockSetStateCallback blockSetStateCallback) {
// eventBus
@ -29,6 +30,19 @@ class BasicInformationLogic extends BaseGetXController {
state.lockSetInfoData.value = event.lockSetInfoData;
blockSetStateCallback();
});
lockSetChangeSetRefreshLockDetailWithTypeSubscription = eventBus
.on<LockSetChangeSetRefreshLockDetailWithType>()
.listen((LockSetChangeSetRefreshLockDetailWithType event) {
if (event.type == 4) {
final int electricQuantity =
int.tryParse(event.setResult['electricQuantity']) ?? 0;
state.lockBasicInfo.value.electricQuantity = electricQuantity;
state.lockBasicInfo.value.electricQuantityDate =
event.setResult['uploadElectricQuantityDate'];
state.lockBasicInfo.refresh();
}
});
}
@override
@ -43,5 +57,6 @@ class BasicInformationLogic extends BaseGetXController {
void onClose() {
super.onClose();
_passCurrentLockInformationEvent?.cancel();
lockSetChangeSetRefreshLockDetailWithTypeSubscription?.cancel();
}
}

View File

@ -23,19 +23,22 @@ class UploadElectricQuantityLogic extends BaseGetXController {
final UploadElectricQuantityState state = UploadElectricQuantityState();
//
Future<void> uploadElectricQuantityRequest(String electricQuantity, String electricQuantityStandby) async {
final KeyOperationRecordEntity entity = await ApiRepository.to.uploadElectricQuantity(
electricQuantity:electricQuantity,
electricQuantityStandby: electricQuantityStandby,
lockId: state.lockSetInfoData.value.lockId.toString(),
isUnShowLoading: false
);
Future<void> uploadElectricQuantityRequest(
String electricQuantity, String electricQuantityStandby) async {
final KeyOperationRecordEntity entity = await ApiRepository.to
.uploadElectricQuantity(
electricQuantity: electricQuantity,
electricQuantityStandby: electricQuantityStandby,
lockId: state.lockSetInfoData.value.lockId.toString(),
isUnShowLoading: false);
if (entity.errorCode!.codeIsSuccessful) {
showToast('锁电量更新成功'.tr, something: () {
eventBus
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
eventBus.fire(
LockSetChangeSetRefreshLockDetailWithType(4, electricQuantity));
eventBus.fire(LockSetChangeSetRefreshLockDetailWithType(4, <String,dynamic>{
'electricQuantity': electricQuantity,
'uploadElectricQuantityDate': state.uploadElectricQuantityDate.value,
}));
eventBus.fire(RefreshLockListInfoDataEvent());
});
}
@ -57,8 +60,10 @@ class UploadElectricQuantityLogic extends BaseGetXController {
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
dismissEasyLoading();
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
@ -67,7 +72,8 @@ class UploadElectricQuantityLogic extends BaseGetXController {
isBeforeAddUser: false,
privateKey: getPrivateKeyList,
);
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
state.sureBtnState.value = 0;
@ -80,6 +86,7 @@ class UploadElectricQuantityLogic extends BaseGetXController {
//
late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() {
_replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
@ -102,20 +109,27 @@ class UploadElectricQuantityLogic extends BaseGetXController {
//
final int battRemCap = reply.data[132];
state.lockSetInfoData.value.lockBasicInfo!.electricQuantity = battRemCap;
state.lockSetInfoData.value.lockBasicInfo!.electricQuantity =
battRemCap;
//
final int battRemCapStandby = reply.data[133];
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityStandby = battRemCapStandby;
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityStandby =
battRemCapStandby;
state.uploadElectricQuantityDate.value = DateTime.now().millisecondsSinceEpoch;
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityDate = DateTime.now().millisecondsSinceEpoch;
uploadElectricQuantityRequest(battRemCap.toString(), battRemCapStandby.toString());
state.uploadElectricQuantityDate.value =
DateTime.now().millisecondsSinceEpoch;
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityDate =
DateTime.now().millisecondsSinceEpoch;
uploadElectricQuantityRequest(
battRemCap.toString(), battRemCapStandby.toString());
break;
case 0x06:
//
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
@ -125,7 +139,6 @@ class UploadElectricQuantityLogic extends BaseGetXController {
privateKey: getPrivateKeyList,
);
break;
default:
//
@ -134,22 +147,27 @@ class UploadElectricQuantityLogic extends BaseGetXController {
}
//
Future<void> getServerDatetime() async{
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData();
if(entity.errorCode!.codeIsSuccessful){
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000;
Future<void> getServerDatetime() async {
final GetServerDatetimeEntity entity =
await ApiRepository.to.getServerDatetimeData();
if (entity.errorCode!.codeIsSuccessful) {
state.differentialTime = entity.data!.date! ~/ 1000 -
DateTime.now().millisecondsSinceEpoch ~/ 1000;
// AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}");
}
}
int getLocalTime(){
return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime;
int getLocalTime() {
return DateTime.now().millisecondsSinceEpoch ~/ 1000 +
state.differentialTime;
}
int getUTCTime(){
final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000, isUtc: true);
int getUTCTime() {
final DateTime utcTime =
DateTime.fromMillisecondsSinceEpoch(getLocalTime() * 1000, isUtc: true);
final String appointmentDate = DateTool().getYMDHNDateStringWithDateTime(utcTime, 1);
final String appointmentDate =
DateTool().getYMDHNDateStringWithDateTime(utcTime, 1);
final int utcTimeValue = DateTool().dateToTimestamp(appointmentDate, 1);
AppLog.log('appointmentDate: $appointmentDate utcTimeValue:$utcTimeValue');
return utcTimeValue ~/ 1000;

View File

@ -50,9 +50,13 @@ class _StarLockMainPageState extends State<StarLockMainPage> with BaseWidget {
if (clearScanDevices) {
BlueManage().scanDevices.clear();
}
if (mounted) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
setState(() {});
}
});
// if (mounted) {
// setState(() {});
// }
}
@override

View File

@ -77,7 +77,7 @@ class LockGroupEditGroupLockRefreshEvent {
///
class LockSetChangeSetRefreshLockDetailWithType {
int type; // 0 1 2 3 4 5
String setResult;
dynamic setResult;
LockSetChangeSetRefreshLockDetailWithType(this.type, this.setResult);
}