From bc440ec377f171072759cdc982202258e40ef043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Tue, 4 Jun 2024 09:12:41 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E9=94=81=E6=97=B6=E9=97=B4=E3=80=81=E6=9B=B4=E6=96=B0=E7=94=B5?= =?UTF-8?q?=E9=87=8F=E4=B8=8A=E4=BC=A0UTC=E6=97=B6=E9=97=B4=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=822=E3=80=81=E4=BF=AE=E6=94=B9=E6=8B=8D?= =?UTF-8?q?=E7=85=A7=E5=A4=B4=E5=83=8F=E4=B8=8A=E4=BC=A0=E6=AF=94=E8=BE=83?= =?UTF-8?q?=E6=85=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io_protocol/io_getStarLockStatusInfo.dart | 2 +- .../uploadElectricQuantity_logic.dart | 46 ++--- .../uploadElectricQuantity_page.dart | 22 +-- .../uploadElectricQuantity_state.dart | 22 +-- .../lockSet/lockTime/lockTime_logic.dart | 184 ++++++++++-------- .../lockSet/lockTime/lockTime_page.dart | 10 +- .../lockSet/lockTime/lockTime_state.dart | 18 +- .../addLock/nearbyLock/nearbyLock_logic.dart | 181 +++++++++-------- .../minePersonInfo_logic.dart | 1 - lib/tools/dateTool.dart | 34 ++++ 10 files changed, 283 insertions(+), 237 deletions(-) diff --git a/lib/blue/io_protocol/io_getStarLockStatusInfo.dart b/lib/blue/io_protocol/io_getStarLockStatusInfo.dart index 1e9f064b..acdc977b 100755 --- a/lib/blue/io_protocol/io_getStarLockStatusInfo.dart +++ b/lib/blue/io_protocol/io_getStarLockStatusInfo.dart @@ -26,7 +26,7 @@ class GetStarLockStatuInfoCommand extends SenderProtocol { @override String toString() { return 'GetStarLockStatuInfoCommand{lockID: $lockID, ' - 'utcTimeStamp:$utcTimeStamp utcTimeStamp: ${DateTool().dateIntToYMDHNString(utcTimeStamp)}, unixTimeStamp:unixTimeStamp unixTimeStamp: ${DateTool().dateIntToYMDHNString(unixTimeStamp)}, ' + 'utcTimeStamp:$utcTimeStamp utcTimeStamp: ${DateTool().dateIntToYMDHNString(utcTimeStamp)}, unixTimeStamp:$unixTimeStamp unixTimeStamp: ${DateTool().dateIntToYMDHNString(unixTimeStamp)}, ' 'userID: $userID, privateKey: $privateKey}'; } diff --git a/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_logic.dart b/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_logic.dart index d279194f..9a921cdd 100755 --- a/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_logic.dart +++ b/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_logic.dart @@ -2,7 +2,9 @@ import 'dart:async'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; +import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart'; +import '../../../../../app_settings/app_settings.dart'; import '../../../../../blue/blue_manage.dart'; import '../../../../../blue/io_protocol/io_getStarLockStatusInfo.dart'; import '../../../../../blue/io_reply.dart'; @@ -11,6 +13,7 @@ import '../../../../../blue/io_tool/manager_event_bus.dart'; import '../../../../../blue/sender_manage.dart'; import '../../../../../network/api_repository.dart'; import '../../../../../tools/baseGetXController.dart'; +import '../../../../../tools/dateTool.dart'; import '../../../../../tools/eventBusEventManage.dart'; import '../../../../../tools/storage.dart'; import '../../../lockOperatingRecord/keyOperationRecord_entity.dart'; @@ -54,13 +57,13 @@ class UploadElectricQuantityLogic extends BaseGetXController { (BluetoothConnectionState deviceConnectionState) async { if (deviceConnectionState == BluetoothConnectionState.connected) { dismissEasyLoading(); - final privateKey = await Storage.getStringList(saveBluePrivateKey); + final List? privateKey = await Storage.getStringList(saveBluePrivateKey); final List getPrivateKeyList = changeStringListToIntList(privateKey!); IoSenderManage.senderGetStarLockStatuInfo( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), - utcTimeStamp: getUTCNetTime(), - unixTimeStamp: getLocalNetTime(), + utcTimeStamp: getUTCTime(), + unixTimeStamp: getLocalTime(), isBeforeAddUser: false, privateKey: getPrivateKeyList, ); @@ -79,7 +82,7 @@ class UploadElectricQuantityLogic extends BaseGetXController { late StreamSubscription _replySubscription; void _initReplySubscription() { _replySubscription = - EventBusManager().eventBus!.on().listen((reply) { + EventBusManager().eventBus!.on().listen((Reply reply) { // 获取锁状态信息 if (reply is GetStarLockStatuInfoReply) { _replyGetStarLockStatusInfo(reply); @@ -98,11 +101,11 @@ class UploadElectricQuantityLogic extends BaseGetXController { cancelBlueConnetctToastTimer(); // 电池剩余电量 - final battRemCap = reply.data[132]; + final int battRemCap = reply.data[132]; state.lockSetInfoData.value.lockBasicInfo!.electricQuantity = battRemCap; // 备用电池剩余电量 - final battRemCapStandby = reply.data[133]; + final int battRemCapStandby = reply.data[133]; state.lockSetInfoData.value.lockBasicInfo!.electricQuantityStandby = battRemCapStandby; state.uploadElectricQuantityDate.value = DateTime.now().millisecondsSinceEpoch; @@ -111,16 +114,18 @@ class UploadElectricQuantityLogic extends BaseGetXController { break; case 0x06: //无权限 - final privateKey = await Storage.getStringList(saveBluePrivateKey); + final List? privateKey = await Storage.getStringList(saveBluePrivateKey); final List getPrivateKeyList = changeStringListToIntList(privateKey!); IoSenderManage.senderGetStarLockStatuInfo( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), - utcTimeStamp: getUTCNetTime(), - unixTimeStamp: getLocalNetTime(), + utcTimeStamp: getUTCTime(), + unixTimeStamp: getLocalTime(), isBeforeAddUser: false, privateKey: getPrivateKeyList, ); + + break; default: //失败 @@ -129,32 +134,29 @@ class UploadElectricQuantityLogic extends BaseGetXController { } // 从服务器获取锁的时间 开锁时传入 - void getServerDatetime() async{ - final entity = await ApiRepository.to.getServerDatetimeData(); + Future getServerDatetime() async{ + final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(); if(entity.errorCode!.codeIsSuccessful){ state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000; - getLocalNetTime(); // AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}"); } } - int getUTCNetTime(){ + int getLocalTime(){ return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime; } - int getLocalNetTime(){ - final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getUTCNetTime()*1000, isUtc: true); - final DateTime localTime = utcTime.toLocal(); + int getUTCTime(){ + final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000, isUtc: true); - // AppLog.log('getUTCNetTime: ${getUTCNetTime()}'); - // AppLog.log('UTC time: $utcTime'); - // AppLog.log('Local time: $localTime localTime.millisecondsSinceEpoch ~/ 1000:${localTime.millisecondsSinceEpoch ~/ 1000}'); - return localTime.millisecondsSinceEpoch ~/ 1000; + final String appointmentDate = DateTool().getYMDHNDateStringWithDateTime(utcTime, 1); + final int utcTimeValue = DateTool().dateToTimestamp(appointmentDate, 1); + AppLog.log('appointmentDate: $appointmentDate utcTimeValue:$utcTimeValue'); + return utcTimeValue ~/ 1000; } @override void onReady() { - // TODO: implement onReady super.onReady(); _initReplySubscription(); @@ -163,13 +165,11 @@ class UploadElectricQuantityLogic extends BaseGetXController { @override void onInit() { - // TODO: implement onInit super.onInit(); } @override void onClose() { - // TODO: implement onClose super.onClose(); _replySubscription.cancel(); } diff --git a/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_page.dart b/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_page.dart index 22f29f45..6d6fd4ff 100755 --- a/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_page.dart +++ b/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_page.dart @@ -3,9 +3,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:star_lock/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_state.dart'; import '../../../../../app_settings/app_colors.dart'; -import '../../../../../blue/blue_manage.dart'; import '../../../../../tools/appRouteObserver.dart'; import '../../../../../tools/dateTool.dart'; import '../../../../../tools/submitBtn.dart'; @@ -22,8 +22,8 @@ class UploadElectricQuantityPage extends StatefulWidget { } class _UploadElectricQuantityPageState extends State with RouteAware { - final logic = Get.put(UploadElectricQuantityLogic()); - final state = Get.find().state; + final UploadElectricQuantityLogic logic = Get.put(UploadElectricQuantityLogic()); + final UploadElectricQuantityState state = Get.find().state; @override Widget build(BuildContext context) { @@ -36,10 +36,10 @@ class _UploadElectricQuantityPageState extends State body: Container( padding: EdgeInsets.all(30.w), child: Column( - children: [ + children: [ Row( mainAxisAlignment: MainAxisAlignment.start, - children: [ + children: [ Expanded( child: Text( TranslationLoader.lanKeys!.updateElectricQuantityTip!.tr, @@ -52,7 +52,7 @@ class _UploadElectricQuantityPageState extends State ), Obx(() => Row( mainAxisAlignment: MainAxisAlignment.start, - children: [ + children: [ Expanded( child: Text( "${"电池1".tr}:${TranslationLoader.lanKeys!.electricQuantity!.tr}:${state.lockBasicInfo.value.electricQuantity ?? ""}%", @@ -64,7 +64,7 @@ class _UploadElectricQuantityPageState extends State visible: state.lockSetInfoData.value.lockFeature!.isSupportBackupBattery == 1, child: Row( mainAxisAlignment: MainAxisAlignment.start, - children: [ + children: [ Expanded( child: Text( "${"电池2".tr}:${TranslationLoader.lanKeys!.electricQuantity!.tr}:${state.lockBasicInfo.value.electricQuantityStandby ?? ""}%", @@ -76,7 +76,7 @@ class _UploadElectricQuantityPageState extends State SizedBox(height: 10.h), Obx(() => Row( mainAxisAlignment: MainAxisAlignment.start, - children: [ + children: [ Expanded( child: Text( "${"电量更新时间".tr}:${DateTool().dateToYMDHNString(state.uploadElectricQuantityDate.value.toString())}", @@ -104,7 +104,6 @@ class _UploadElectricQuantityPageState extends State @override void didChangeDependencies() { - // TODO: implement didChangeDependencies super.didChangeDependencies(); /// 路由订阅 @@ -113,7 +112,6 @@ class _UploadElectricQuantityPageState extends State @override void dispose() { - // TODO: implement dispose /// 取消路由订阅 AppRouteObserver().routeObserver.unsubscribe(this); super.dispose(); @@ -148,7 +146,9 @@ class _UploadElectricQuantityPageState extends State void didPushNext() { super.didPushNext(); logic.cancelBlueConnetctToastTimer(); - if (EasyLoading.isShow) EasyLoading.dismiss(animation: true); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } state.ifCurrentScreen.value = false; state.sureBtnState.value = 0; } diff --git a/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_state.dart b/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_state.dart index 0cda24a0..8d5e5eec 100755 --- a/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_state.dart +++ b/lib/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_state.dart @@ -3,24 +3,24 @@ import 'package:get/get.dart'; import '../../lockSet/lockSetInfo_entity.dart'; -class UploadElectricQuantityState { - var lockSetInfoData = LockSetInfoData().obs; - var lockBasicInfo = LockBasicInfo().obs; - var uploadElectricQuantityDate = 0.obs; - int differentialTime = 0; - - var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 - var sureBtnState = 0.obs;// 0普通状态可用 1不可用 +class UploadElectricQuantityState {// 0普通状态可用 1不可用 UploadElectricQuantityState() { - var map = Get.arguments; - if(map["lockSetInfoData"]!=null){ - lockSetInfoData.value = map["lockSetInfoData"]; + final map = Get.arguments; + if(map['lockSetInfoData']!=null){ + lockSetInfoData.value = map['lockSetInfoData']; if(lockSetInfoData.value.lockBasicInfo!=null){ lockBasicInfo.value = lockSetInfoData.value.lockBasicInfo!; uploadElectricQuantityDate.value = lockSetInfoData.value.lockBasicInfo!.electricQuantityDate!; } } } + Rx lockSetInfoData = LockSetInfoData().obs; + Rx lockBasicInfo = LockBasicInfo().obs; + RxInt uploadElectricQuantityDate = 0.obs; + int differentialTime = 0; + + RxBool ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + RxInt sureBtnState = 0.obs; } \ No newline at end of file diff --git a/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart b/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart index 961bdf42..f3893ea9 100755 --- a/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart +++ b/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart @@ -1,8 +1,11 @@ import 'dart:async'; +import 'package:date_format/date_format.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; +import 'package:star_lock/app_settings/app_settings.dart'; +import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart'; import '../../../../blue/blue_manage.dart'; import '../../../../blue/io_protocol/io_getStarLockStatusInfo.dart'; @@ -23,65 +26,69 @@ class LockTimeLogic extends BaseGetXController{ // 获取解析后的数据 late StreamSubscription _replySubscription; void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((reply) { + _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) { if(reply is TimingReply) { _replyTiming(reply); } // 获取锁状态 - // if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) { - // _replyGetStarLockStatusInfo(reply); - // } + if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) { + _replyGetStarLockStatusInfo(reply); + } }); } - // 获取锁状态数据解析 - // Future _replyGetStarLockStatusInfo(Reply reply) async { - // int status = reply.data[2]; - // switch (status) { - // case 0x00: - // //成功 - // cancelBlueConnetctToastTimer(); - // dismissEasyLoading(); - // - // // 有效时间 - // var indate = reply.data.sublist(149, 153); - // int indateValue = ((0xff & indate[(0)]) << 24 | - // (0xff & indate[1]) << 16 | - // (0xff & indate[2]) << 8 | - // (0xFF & indate[3])); - // state.dateTime.value = DateTool().dateToYMDHNString("$indateValue"); - // break; - // case 0x06: - // //需要鉴权 - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // IoSenderManage.senderGetStarLockStatuInfo( - // lockID: BlueManage().connectDeviceName, - // userID: await Storage.getUid(), - // isBeforeAddUser: false, - // privateKey: getPrivateKeyList, - // ); - // break; - // default: - // //失败 - // break; - // } - // } +// 获取锁状态数据解析 + Future _replyGetStarLockStatusInfo(Reply reply) async { + final int status = reply.data[2]; + switch (status) { + case 0x00: + //成功 + cancelBlueConnetctToastTimer(); + dismissEasyLoading(); + + // 有效时间 + final List indate = reply.data.sublist(150, 154); + final int indateValue = (0xff & indate[0]) << 24 | + (0xff & indate[1]) << 16 | + (0xff & indate[2]) << 8 | + (0xFF & indate[3]); + AppLog.log('indate:$indate indateValue:$indateValue'); + state.dateTime.value = DateTool().dateToYMDHNString('$indateValue'); + break; + case 0x06: + //需要鉴权 + final List? privateKey = await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = changeStringListToIntList(privateKey!); + + IoSenderManage.senderGetStarLockStatuInfo( + lockID: BlueManage().connectDeviceName, + userID: await Storage.getUid(), + utcTimeStamp: 0, + unixTimeStamp: 0, + isBeforeAddUser: false, + privateKey: getPrivateKeyList, + ); + break; + default: + //失败 + break; + } + } // 校时数据解析 Future _replyTiming(Reply reply) async { - int status = reply.data[2]; + final int status = reply.data[2]; switch(status){ case 0x00: //成功 - String dataEime = DateTool().dateToYMDHNString("${getUTCNetTime()}"); + final String dataEime = DateTool().dateToYMDHNString('${getLocalTime()}'); state.dateTime.value = dataEime; state.sureBtnState.value = 0; cancelBlueConnetctToastTimer(); dismissEasyLoading(); - showToast("锁时间更新成功".tr); + showToast('锁时间更新成功'.tr); break; case 0x06: //无权限 @@ -105,20 +112,19 @@ class LockTimeLogic extends BaseGetXController{ }); BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { if (connectionState == BluetoothConnectionState.connected) { - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = changeStringListToIntList(privateKey!); - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = changeStringListToIntList(token!); + final List? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); - var signKey = await Storage.getStringList(saveBlueSignKey); - List getSignKeyList = changeStringListToIntList(signKey!); + final List? signKey = await Storage.getStringList(saveBlueSignKey); + final List getSignKeyList = changeStringListToIntList(signKey!); IoSenderManage.senderTimingCommand( lockID:BlueManage().connectDeviceName, userID:await Storage.getUid(), - // nowTime:DateTime.now().millisecondsSinceEpoch~/1000, - nowTime: getUTCNetTime(), + nowTime: getLocalTime(), token:getTokenList, needAuthor:1, signKey:getSignKeyList, @@ -135,37 +141,39 @@ class LockTimeLogic extends BaseGetXController{ }); } - // 获取锁状态 更新电量 - // Future getStarLockStatus() async { - // showEasyLoading(); - // showBlueConnetctToastTimer(action: () { - // dismissEasyLoading(); - // }); - // BlueManage().bludSendData(BlueManage().connectDeviceName, - // (BluetoothConnectionState deviceConnectionState) async { - // if (deviceConnectionState == BluetoothConnectionState.connected) { - // dismissEasyLoading(); - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // IoSenderManage.senderGetStarLockStatuInfo( - // lockID: BlueManage().connectDeviceName, - // userID: await Storage.getUid(), - // isBeforeAddUser: false, - // privateKey: getPrivateKeyList, - // ); - // } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { - // dismissEasyLoading(); - // cancelBlueConnetctToastTimer(); - // if (state.ifCurrentScreen.value == true) { - // showBlueConnetctToast(); - // } - // } - // }); - // } +// 获取锁状态 更新时间 + Future getStarLockStatus() async { + showEasyLoading(); + showBlueConnetctToastTimer(action: () { + dismissEasyLoading(); + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { + final List? privateKey = await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = changeStringListToIntList(privateKey!); + + IoSenderManage.senderGetStarLockStatuInfo( + lockID: BlueManage().connectDeviceName, + userID: await Storage.getUid(), + utcTimeStamp: 0, + unixTimeStamp: 0, + isBeforeAddUser: false, + privateKey: getPrivateKeyList, + ); + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + if (state.ifCurrentScreen.value == true) { + showBlueConnetctToast(); + } + } + }); + } // 从网关获取时间 - void getLockTimeFromGateway() async{ - var entity = await ApiRepository.to.getLockTimeFromGateway( + Future getLockTimeFromGateway() async{ + final GetServerDatetimeEntity entity = await ApiRepository.to.getLockTimeFromGateway( lockId: state.lockSetInfoData.value.lockId.toString(), ); if(entity.errorCode!.codeIsSuccessful){ @@ -174,41 +182,45 @@ class LockTimeLogic extends BaseGetXController{ } // 从服务器获取锁的时间 开锁时传入 - void getServerDatetime() async{ - var entity = await ApiRepository.to.getServerDatetimeData(); + Future 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}"); + getStarLockStatus(); } } - int getUTCNetTime(){ + int getLocalTime(){ return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime; } + int getUTCTime(){ + final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000, isUtc: true); + + final String appointmentDate = DateTool().getYMDHNDateStringWithDateTime(utcTime, 1); + final int utcTimeValue = DateTool().dateToTimestamp(appointmentDate, 1); + AppLog.log('appointmentDate: $appointmentDate utcTimeValue:$utcTimeValue'); + return utcTimeValue ~/ 1000; + } + @override void onReady() { - // TODO: implement onReady super.onReady(); _initReplySubscription(); - // getStarLockStatus(); // getLockTimeFromGateway(); getServerDatetime(); } @override void onInit() { - // TODO: implement onInit super.onInit(); - - // _getLockStatus(); } @override void onClose() { - // TODO: implement onClose super.onClose(); _replySubscription.cancel(); } diff --git a/lib/main/lockDetail/lockSet/lockTime/lockTime_page.dart b/lib/main/lockDetail/lockSet/lockTime/lockTime_page.dart index 06883e72..69643e8b 100755 --- a/lib/main/lockDetail/lockSet/lockTime/lockTime_page.dart +++ b/lib/main/lockDetail/lockSet/lockTime/lockTime_page.dart @@ -77,7 +77,6 @@ class _LockTimePageState extends State with RouteAware{ @override void didChangeDependencies() { - // TODO: implement didChangeDependencies super.didChangeDependencies(); /// 路由订阅 @@ -86,7 +85,6 @@ class _LockTimePageState extends State with RouteAware{ @override void dispose() { - // TODO: implement dispose /// 取消路由订阅 AppRouteObserver().routeObserver.unsubscribe(this); super.dispose(); @@ -104,7 +102,9 @@ class _LockTimePageState extends State with RouteAware{ void didPop() { super.didPop(); logic.cancelBlueConnetctToastTimer(); - if (EasyLoading.isShow) EasyLoading.dismiss(animation: true); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } state.ifCurrentScreen.value = false; state.sureBtnState.value = 0; } @@ -121,7 +121,9 @@ class _LockTimePageState extends State with RouteAware{ void didPushNext() { super.didPushNext(); logic.cancelBlueConnetctToastTimer(); - if (EasyLoading.isShow) EasyLoading.dismiss(animation: true); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } state.ifCurrentScreen.value = false; state.sureBtnState.value = 0; } diff --git a/lib/main/lockDetail/lockSet/lockTime/lockTime_state.dart b/lib/main/lockDetail/lockSet/lockTime/lockTime_state.dart index c28d6727..2ec98723 100755 --- a/lib/main/lockDetail/lockSet/lockTime/lockTime_state.dart +++ b/lib/main/lockDetail/lockSet/lockTime/lockTime_state.dart @@ -2,16 +2,16 @@ import 'package:get/get.dart'; import '../lockSet/lockSetInfo_entity.dart'; -class LockTimeState{ - var lockSetInfoData = LockSetInfoData().obs; - var dateTime = "".obs; - int differentialTime = 0; - - var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 - var sureBtnState = 0.obs;// 0普通状态(可用) 1连接中(不可用) +class LockTimeState{// 0普通状态(可用) 1连接中(不可用) LockTimeState() { - var map = Get.arguments; - lockSetInfoData.value = map["lockSetInfoData"]; + final map = Get.arguments; + lockSetInfoData.value = map['lockSetInfoData']; } + Rx lockSetInfoData = LockSetInfoData().obs; + RxString dateTime = ''.obs; + int differentialTime = 0; + + RxBool ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + RxInt sureBtnState = 0.obs; } \ No newline at end of file diff --git a/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart b/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart index cd8e1f3a..3542b31b 100755 --- a/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart +++ b/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart @@ -13,6 +13,7 @@ import 'package:star_lock/blue/io_protocol/io_getPrivateKey.dart'; import 'package:star_lock/blue/io_protocol/io_getPublicKey.dart'; import 'package:star_lock/blue/io_protocol/io_otaUpgrade.dart'; import 'package:star_lock/blue/io_protocol/io_processOtaUpgrade.dart'; +import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart'; import 'package:star_lock/mine/addLock/nearbyLock/nearbyLock_page.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/widget/permission/permission_dialog.dart'; @@ -26,6 +27,7 @@ import '../../../blue/io_tool/io_tool.dart'; import '../../../blue/io_tool/manager_event_bus.dart'; import '../../../blue/sender_manage.dart'; import '../../../network/api_repository.dart'; +import '../../../tools/dateTool.dart'; import '../../../tools/storage.dart'; import 'nearbyLock_state.dart'; @@ -68,7 +70,7 @@ class NearbyLockLogic extends BaseGetXController { void _initReplySubscription() { _replySubscription = - EventBusManager().eventBus!.on().listen((reply) { + EventBusManager().eventBus!.on().listen((Reply reply) { if (reply is GetPublicKeyReply) { _replyGetPublicKey(reply); } @@ -110,8 +112,8 @@ class NearbyLockLogic extends BaseGetXController { //成功 AppLog.log('获取公钥成功'); // 储存公钥 - var publicKey = reply.data.sublist(3); - var saveStrList = changeIntListToStringList(publicKey); + final List publicKey = reply.data.sublist(3); + final List saveStrList = changeIntListToStringList(publicKey); Storage.setStringList(saveBluePublicKey, saveStrList); // 获取私钥 @@ -140,22 +142,21 @@ class NearbyLockLogic extends BaseGetXController { reply.data.removeAt(0); // 私钥 - List privateKey = reply.data.sublist(0, 16); - var savePrivateKeyList = changeIntListToStringList(privateKey); + final List privateKey = reply.data.sublist(0, 16); + final List savePrivateKeyList = changeIntListToStringList(privateKey); Storage.setStringList(saveBluePrivateKey, savePrivateKeyList); // signKey - List signKey = reply.data.sublist(16, 32); - var saveSignKeyList = changeIntListToStringList(signKey); + final List signKey = reply.data.sublist(16, 32); + final List saveSignKeyList = changeIntListToStringList(signKey); Storage.setStringList(saveBlueSignKey, saveSignKeyList); // 时间戳 - List timestamp = reply.data.sublist(32, 36); - state.timestampValue = ((0xff & timestamp[(0)]) << 24 | + final List timestamp = reply.data.sublist(32, 36); + state.timestampValue = (0xff & timestamp[0]) << 24 | (0xff & timestamp[1]) << 16 | (0xff & timestamp[2]) << 8 | - (0xFF & timestamp[3])); - + (0xFF & timestamp[3]); showTitleEasyLoading('获取锁信息 3/3'); _getStarLockStatus(); break; @@ -167,138 +168,138 @@ class NearbyLockLogic extends BaseGetXController { // 获取星锁状态 Future _replyGetStarLockStatusInfo(Reply reply) async { - int status = reply.data[2]; + final int status = reply.data[2]; switch (status) { case 0x00: //成功 AppLog.log('获取锁状态成功'); // 厂商名称 - var index = 3; - var vendor = reply.data.sublist(index, index + 20); - var vendorStr = utf8String(vendor); + int index = 3; + final List vendor = reply.data.sublist(index, index + 20); + final String vendorStr = utf8String(vendor); state.lockInfo['vendor'] = vendorStr; // state.lockInfo["vendor"] = "XL"; index = index + 20; AppLog.log('厂商名称 vendorStr:$vendorStr'); // 锁设备类型 - var product = reply.data[index]; + final int product = reply.data[index]; state.lockInfo['product'] = product; index = index + 1; AppLog.log('锁设备类型 product:$product'); // 产品名称 - var model = reply.data.sublist(index, index + 20); - var modelStr = utf8String(model); + final List model = reply.data.sublist(index, index + 20); + final String modelStr = utf8String(model); state.lockInfo['model'] = modelStr; // state.lockInfo["model"] = "JL-BLE-01"; index = index + 20; AppLog.log('产品名称 mmodelStr:$modelStr'); // 软件版本 - var fwVersion = reply.data.sublist(index, index+20); - var fwVersionStr = utf8String(fwVersion); + final List fwVersion = reply.data.sublist(index, index+20); + final String fwVersionStr = utf8String(fwVersion); state.lockInfo['fwVersion'] = fwVersionStr; index = index + 20; AppLog.log('软件版本 fwVersionStr:$fwVersionStr'); // 硬件版本 - var hwVersion = reply.data.sublist(index, index+20); - var hwVersionStr = utf8String(hwVersion); + final List hwVersion = reply.data.sublist(index, index+20); + final String hwVersionStr = utf8String(hwVersion); state.lockInfo['hwVersion'] = hwVersionStr; index = index + 20; AppLog.log('硬件版本 hwVersionStr:$hwVersionStr'); // 厂商序列号 - var serialNum0 = reply.data.sublist(index, index + 16); - var serialNum0Str = utf8String(serialNum0); + final List serialNum0 = reply.data.sublist(index, index + 16); + final String serialNum0Str = utf8String(serialNum0); state.lockInfo['serialNum0'] = serialNum0Str; // state.lockInfo["serialNum0"] = "${DateTime.now().millisecondsSinceEpoch ~/ 10}"; index = index + 16; AppLog.log('厂商序列号 serialNum0Str:${serialNum0Str.length}'); // 成品商序列号 - var serialNum1 = reply.data.sublist(index, index + 16); - var serialNum1Str = utf8String(serialNum1); + final List serialNum1 = reply.data.sublist(index, index + 16); + final String serialNum1Str = utf8String(serialNum1); state.lockInfo['serialNum1'] = serialNum1Str; index = index + 16; AppLog.log('成品商序列号 serialNum1Str:$serialNum1Str'); // 蓝牙名称 - var btDeviceName = reply.data.sublist(index, index + 16); - var btDeviceNameStr = utf8String(btDeviceName); + final List btDeviceName = reply.data.sublist(index, index + 16); + final String btDeviceNameStr = utf8String(btDeviceName); state.lockInfo['btDeviceName'] = btDeviceNameStr; index = index + 16; AppLog.log('蓝牙名称 btDeviceNameStr:$btDeviceNameStr'); // 电池剩余电量 - var battRemCap = reply.data[index]; + final int battRemCap = reply.data[index]; state.lockInfo['electricQuantity'] = battRemCap; index = index + 1; AppLog.log('电池剩余电量 battRemCap:$battRemCap'); // 备用电池剩余电量 - var battRemCapStandby = reply.data[index]; + final int battRemCapStandby = reply.data[index]; state.lockInfo['electricQuantityStandby'] = battRemCapStandby; index = index + 1; AppLog.log('电池剩余电量 battRemCap:$battRemCap'); // 重置次数 - var restoreCounter = reply.data.sublist(index, index + 2); + final List restoreCounter = reply.data.sublist(index, index + 2); state.lockInfo['restoreCount'] = restoreCounter[0] * 256 + restoreCounter[1]; index = index + 2; AppLog.log('重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}'); // 重置时间 - var restoreDate = reply.data.sublist(index, index + 4); - int restoreDateValue = ((0xff & restoreDate[(0)]) << 24 | + final List restoreDate = reply.data.sublist(index, index + 4); + final int restoreDateValue = (0xff & restoreDate[0]) << 24 | (0xff & restoreDate[1]) << 16 | (0xff & restoreDate[2]) << 8 | - (0xFF & restoreDate[3])); + (0xFF & restoreDate[3]); // String restoreDateStr = DateTool().dateToYMDHNSString(restoreDateValue.toString()); state.lockInfo['restoreDate'] = restoreDateValue * 1000; index = index + 4; AppLog.log('重置时间 restoreDateValue:$restoreDateValue'); // 主控芯片型号 - var icPartNo = reply.data.sublist(index, index + 10); - var icPartNoStr = utf8String(icPartNo); + final List icPartNo = reply.data.sublist(index, index + 10); + final String icPartNoStr = utf8String(icPartNo); state.lockInfo['icPartNo'] = icPartNoStr; index = index + 10; AppLog.log('主控芯片型号 icPartNoStr:$icPartNoStr'); // 有效时间 - var indate = reply.data.sublist(index, index + 4); - int indateValue = ((0xff & indate[(0)]) << 24 | + final List indate = reply.data.sublist(index, index + 4); + final int indateValue = (0xff & indate[0]) << 24 | (0xff & indate[1]) << 16 | (0xff & indate[2]) << 8 | - (0xFF & indate[3])); + (0xFF & indate[3]); // String indateStr = DateTool().dateToYMDHNSString("$indateValue"); state.lockInfo['indate'] = indateValue * 1000; index = index + 4; AppLog.log('有效时间 indateValue:$indateValue'); // mac地址 - var macAddress = reply.data.sublist(index, index + 20); - var macAddressStr = utf8String(macAddress); + final List macAddress = reply.data.sublist(index, index + 20); + final String macAddressStr = utf8String(macAddress); state.lockInfo['mac'] = macAddressStr; index = index + 20; AppLog.log('mac地址 macAddressStr:$macAddressStr'); // 锁特征值字符串长度 - var featureValueLength = reply.data[index]; + final int featureValueLength = reply.data[index]; index = index + 1; AppLog.log('锁特征值字符串长度 featureValueLength:$featureValueLength'); // 锁特征值说明(本机能支持的功能) // 获取到锁给的字符数组 - var featureNetxLength = index + featureValueLength; + final int featureNetxLength = index + featureValueLength; if (reply.data.length < featureNetxLength) { showToast('锁数据异常,请重试'); return; } - var featureValue = reply.data.sublist(index, index + featureValueLength); - String featureValueStr = asciiString(featureValue); + final List featureValue = reply.data.sublist(index, index + featureValueLength); + final String featureValueStr = asciiString(featureValue); state.featureValue = featureValueStr; // List allFeatureValueTwoList = charListChangeIntList(featureValue); // AppLog.log("featureValueLength:$featureValueLength featureValue:$featureValue \n featureValueStr:$featureValueStr"); @@ -306,18 +307,18 @@ class NearbyLockLogic extends BaseGetXController { AppLog.log('锁特征值字符串 featureValueStr:$featureValueStr'); // 使能特征值字符串长度 - var featureEnValLength = reply.data[index]; + final int featureEnValLength = reply.data[index]; index = index + 1; AppLog.log('使能特征值字符串长度 featureEnValLength:$featureEnValLength'); // 使能锁特征值说明(本机启用的功能) - var featureEnNextLength = index + featureEnValLength; + final int featureEnNextLength = index + featureEnValLength; if (reply.data.length < featureEnNextLength) { showToast('锁数据异常,请重试'); return; } - var featureEnVal = reply.data.sublist(index, index + featureEnValLength); - String featureEnValStr = asciiString(featureEnVal); + final List featureEnVal = reply.data.sublist(index, index + featureEnValLength); + final String featureEnValStr = asciiString(featureEnVal); state.featureSettingValue = featureEnValStr; // List allFeatureEnValTwoList = charListChangeIntList(featureEnVal); // AppLog.log("featureEnValLength:$featureEnValLength featureEnVal:$featureEnVal \n featureEnValStr:$featureEnValStr"); @@ -327,11 +328,11 @@ class NearbyLockLogic extends BaseGetXController { // 支持的带参数特征值的总条目数 // var featureParaTotal = reply.data[index]; - var featureParaTotalList = reply.data.sublist(index); + final List featureParaTotalList = reply.data.sublist(index); state.featureSettingParams = featureParaTotalList; AppLog.log('featureParaTotalList:$featureParaTotalList'); - Get.toNamed(Routers.lockAddressGaoDePage, arguments: { + Get.toNamed(Routers.lockAddressGaoDePage, arguments: { 'pwdTimestamp': state.timestampValue * 1000, 'lockInfo': state.lockInfo, 'featureValue': state.featureValue, @@ -342,8 +343,8 @@ class NearbyLockLogic extends BaseGetXController { break; case 0x06: //无权限 - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = changeStringListToIntList(privateKey!); // IoSenderManage.senderGetLockStatu( // lockID:BlueManage().connectDeviceName, // userID:await Storage.getUid(), @@ -352,8 +353,8 @@ class NearbyLockLogic extends BaseGetXController { IoSenderManage.senderGetStarLockStatuInfo( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), - utcTimeStamp: getUTCNetTime(), - unixTimeStamp: getLocalNetTime(), + utcTimeStamp: getUTCTime(), + unixTimeStamp: getLocalTime(), isBeforeAddUser: true, privateKey: getPrivateKeyList, ); @@ -373,14 +374,14 @@ class NearbyLockLogic extends BaseGetXController { // dismissEasyLoading(); AppLog.log('开始获取锁状态'); - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = changeStringListToIntList(privateKey!); IoSenderManage.senderGetStarLockStatuInfo( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), - utcTimeStamp: getUTCNetTime(), - unixTimeStamp: getLocalNetTime(), + utcTimeStamp: getUTCTime(), + unixTimeStamp: getLocalTime(), isBeforeAddUser: true, privateKey: getPrivateKeyList, ); @@ -394,12 +395,12 @@ class NearbyLockLogic extends BaseGetXController { BlueManage().startScan(2000, (List list) { state.devices.clear(); for (int i = 0; i < list.length; i++) { - ScanResult device = list[i]; - if (((device.advertisementData.serviceUuids.isNotEmpty + final ScanResult device = list[i]; + if ((device.advertisementData.serviceUuids.isNotEmpty ? device.advertisementData.serviceUuids[0] : '') .toString()[31] != - '1')) { + '1') { state.devices.add(list[i]); } } @@ -431,16 +432,16 @@ class NearbyLockLogic extends BaseGetXController { //手动升级 Future otaUpdate() async { - var status = await PermissionDialog.requestStorage(); + final bool status = await PermissionDialog.requestStorage(); if (status != true) { return; } - FilePickerResult? result = await FilePicker.platform.pickFiles(); + final FilePickerResult? result = await FilePicker.platform.pickFiles(); if (result == null || result.files.single.path is! String) { return; } - File file = File(result.files.single.path!); - Uint8List data = await file.readAsBytes(); + final File file = File(result.files.single.path!); + final Uint8List data = await file.readAsBytes(); headJson = await getHeadFile(data); if (headJson is! Map) { return; @@ -449,9 +450,9 @@ class NearbyLockLogic extends BaseGetXController { if (otaBin == null) { return; } - String md5Str = md5.convert(otaBin!).toString(); + final String md5Str = md5.convert(otaBin!).toString(); headJson!['fwMd5'] = md5Str; - blueOTAUpgrade(headJson!, [0, 0, 0, 0]); + blueOTAUpgrade(headJson!, [0, 0, 0, 0]); } //蓝牙操作 ota 升级 @@ -463,7 +464,7 @@ class NearbyLockLogic extends BaseGetXController { BlueManage().blueSendData(deviceName!, (BluetoothConnectionState deviceConnectionState) async { if (deviceConnectionState == BluetoothConnectionState.connected) { - String uid = await Storage.getUid() ?? ''; + final String uid = await Storage.getUid() ?? ''; BlueManage().writeCharacteristicWithResponse(OTAUpgradeCommand( lockID: deviceName, userID: uid, @@ -488,29 +489,29 @@ class NearbyLockLogic extends BaseGetXController { if (!state.otaUpdateIng.value) { return; } - int length = otaBin?.length ?? 0; + final int length = otaBin?.length ?? 0; if (otaCount == 0) { //首次 - int difference = length % 240; + final int difference = length % 240; otaCount = length ~/ 240 + (difference > 0 ? 1 : 0); startSecond = DateTime.now().millisecondsSinceEpoch ~/ 1000; } if (otaCount <= otaIndex) { - int now = DateTime.now().millisecondsSinceEpoch ~/ 1000; - String msg = + final int now = DateTime.now().millisecondsSinceEpoch ~/ 1000; + final String msg = '传输完成 时间:${now - startSecond}秒 otaCount:$otaCount otaIndex:$otaIndex '; closeOTADAta(); AppLog.log(msg); // showToast(msg); return; } - int star = otaIndex * 240; + final int star = otaIndex * 240; int end = (otaIndex + 1) * 240; if (end > length) { end = length; } - int size = end - star; - List data = otaBin!.sublist(star, end); + final int size = end - star; + final List data = otaBin!.sublist(star, end); state.otaProgress.value = otaIndex / otaCount; await BlueManage().writeCharacteristicWithResponse( ProcessOtaUpgradeCommand(index: otaIndex, size: size, data: data) @@ -594,7 +595,7 @@ class NearbyLockLogic extends BaseGetXController { return null; } AppLog.log(metaStr); - var meta = jsonDecode(metaStr); + final meta = jsonDecode(metaStr); if (meta is! Map) { showToast('解析元数据失败,请选择正确的文件'.tr); return null; @@ -604,11 +605,11 @@ class NearbyLockLogic extends BaseGetXController { //检测升级文件并读取 bin Future checkFile(Uint8List data, Map meta) async { - num binOffset = 16 + (meta['metaLen'] ?? 0); + final num binOffset = 16 + (meta['metaLen'] ?? 0); // 获取固件数据部分 - Uint8List bin = data.sublist(binOffset.toInt(), data.length); + final Uint8List bin = data.sublist(binOffset.toInt(), data.length); //md5 校验有问题,暂时不解析 - String md5Str = md5.convert(bin).toString().toUpperCase(); + final String md5Str = md5.convert(bin).toString().toUpperCase(); // AppLog.log('---> $md5Str ${meta['fwMd5']}'); if (md5Str != meta['fwMd5']) { showToast('文件校验失败 0x02'.tr); @@ -622,27 +623,25 @@ class NearbyLockLogic extends BaseGetXController { } // 从服务器获取锁的时间 开锁时传入 - void getServerDatetime() async{ - var entity = await ApiRepository.to.getServerDatetimeData(); + Future getServerDatetime() async{ + final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(); if(entity.errorCode!.codeIsSuccessful){ state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000; - getLocalNetTime(); // AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}"); } } - int getUTCNetTime(){ + int getLocalTime(){ return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime; } - int getLocalNetTime(){ - DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getUTCNetTime()*1000, isUtc: true); - DateTime localTime = utcTime.toLocal(); + int getUTCTime(){ + final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000, isUtc: true); - // AppLog.log('getUTCNetTime: ${getUTCNetTime()}'); - // AppLog.log('UTC time: $utcTime'); - // AppLog.log('Local time: $localTime localTime.millisecondsSinceEpoch ~/ 1000:${localTime.millisecondsSinceEpoch ~/ 1000}'); - return localTime.millisecondsSinceEpoch ~/ 1000; + final String appointmentDate = DateTool().getYMDHNDateStringWithDateTime(utcTime, 1); + final int utcTimeValue = DateTool().dateToTimestamp(appointmentDate, 1); + AppLog.log('appointmentDate: $appointmentDate utcTimeValue:$utcTimeValue'); + return utcTimeValue ~/ 1000; } @override diff --git a/lib/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_logic.dart b/lib/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_logic.dart index 00346532..bd2d7ebf 100755 --- a/lib/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_logic.dart +++ b/lib/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_logic.dart @@ -95,7 +95,6 @@ class MinePersonInfoLogic extends BaseGetXController { source: ImageSource.camera, maxHeight: 250, maxWidth: 250, - imageQuality: 80 ); if (photo != null) { state.image = photo; diff --git a/lib/tools/dateTool.dart b/lib/tools/dateTool.dart index 3e986e92..2da0b052 100755 --- a/lib/tools/dateTool.dart +++ b/lib/tools/dateTool.dart @@ -116,6 +116,40 @@ class DateTool { return dateStr; } + /// 根据传入的PDuration及时间类型获取时间字符串 + /// type 1: 年月日时分(2023-01-01 12:00) 2: 年月日(2023-01-01) 3: 时分(12:00) + String getYMDHNDateStringWithDateTime(DateTime p, int type) { + final int year = p.year == 0 ? DateTime.now().year : p.year; + final int month = p.month == 0 ? DateTime.now().month : p.month; + final int day = p.day == 0 ? DateTime.now().day : p.day; + final int hour = p.hour; + final int minute = p.minute; + + String dateStr = ''; + switch (type) { + case 1: + // 年月日时分(2023-01-01 12:48) + dateStr = + '$year-${month!.toString().padLeft(2, '0')}-${day.toString().padLeft(2, '0')} ${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}'; + break; + case 2: + // 年月日(2023-01-01) + dateStr = + '$year-${month!.toString().padLeft(2, '0')}-${day.toString().padLeft(2, '0')}'; + break; + case 3: + // 时分(12:05) + dateStr = + '${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}'; + break; + default: + dateStr = + '$year-${month!.toString().padLeft(2, '0')}-${day.toString().padLeft(2, '0')} ${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}'; + break; + } + return dateStr; + } + /// 日期转化为时间戳 /// type 0: 12:00 1: 其他 int dateToTimestamp(String dateStr, int type) {