1,发送钥匙成功后返回列表刷新

This commit is contained in:
Daisy 2023-08-31 18:50:28 +08:00
parent 7f44198536
commit d6570450cf
8 changed files with 182 additions and 158 deletions

View File

@ -1,4 +1,3 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
@ -21,7 +20,8 @@ class AuthorizedAdminLogic extends BaseGetXController {
// //
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) async { _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((reply) async {
// //
if (reply is TransferPermissionsReply) { if (reply is TransferPermissionsReply) {
var token = reply.data.sublist(2, 6); var token = reply.data.sublist(2, 6);
@ -42,7 +42,8 @@ class AuthorizedAdminLogic extends BaseGetXController {
// //
print("${reply.commandType!.typeValue} 需要鉴权"); print("${reply.commandType!.typeValue} 需要鉴权");
var privateKey = await Storage.getStringList(saveBluePrivateKey); var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
var publicKey = await Storage.getStringList(saveBluePublicKey); var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!); List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
@ -57,8 +58,7 @@ class AuthorizedAdminLogic extends BaseGetXController {
needAuthor: 1, needAuthor: 1,
publicKey: publicKeyDataList, publicKey: publicKeyDataList,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
token: getTokenList token: getTokenList);
);
break; break;
case 0x07: case 0x07:
// //
@ -82,7 +82,9 @@ class AuthorizedAdminLogic extends BaseGetXController {
// //
Future<void> transferPermissionsAction() async { Future<void> transferPermissionsAction() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async { BlueManage().judgeReconnect(
BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName,
(DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) { if (state == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey); var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -103,8 +105,7 @@ class AuthorizedAdminLogic extends BaseGetXController {
needAuthor: 1, needAuthor: 1,
publicKey: publicKeyDataList, publicKey: publicKeyDataList,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
token: getTokenList token: getTokenList);
);
} }
}); });
} }
@ -121,7 +122,6 @@ class AuthorizedAdminLogic extends BaseGetXController {
void onInit() { void onInit() {
// TODO: implement onInit // TODO: implement onInit
super.onInit(); super.onInit();
} }
@override @override
@ -129,5 +129,4 @@ class AuthorizedAdminLogic extends BaseGetXController {
// TODO: implement onClose // TODO: implement onClose
_replySubscription.cancel(); _replySubscription.cancel();
} }
} }

View File

@ -302,7 +302,7 @@ class _AuthorizedAdminPageState extends State<AuthorizedAdminPage> {
btnName: '完成', btnName: '完成',
onClick: () { onClick: () {
_isSendSuccess = false; _isSendSuccess = false;
setState(() {}); Navigator.pop(context, true);
}), }),
SizedBox( SizedBox(
height: 10.h, height: 10.h,

View File

@ -69,6 +69,11 @@ class _AuthorizedAdminListPageState extends State<AuthorizedAdminListPage> {
arguments: { arguments: {
"lockMainEntity": lockMainEntity, "lockMainEntity": lockMainEntity,
"keyInfo": keyInfo "keyInfo": keyInfo
}).then((val) {
if (val != null) {
mockNetworkDataRequest();
setState(() {});
}
}); });
}, },
), ),

View File

@ -82,6 +82,11 @@ class _ElectronicKeyListPageState extends State<ElectronicKeyListPage> {
arguments: { arguments: {
"lockMainEntity": lockMainEntity, "lockMainEntity": lockMainEntity,
"keyInfo": keyInfo "keyInfo": keyInfo
}).then((val) {
if (val != null) {
mockNetworkDataRequest();
setState(() {});
}
}); });
}, },
), ),

View File

@ -80,13 +80,14 @@ class _SendElectronicKeyPageState extends State<SendElectronicKeyPage> {
} }
Widget indexChangeWidget() { Widget indexChangeWidget() {
if (_isSendSuccess) {
return sendElectronicKeySucceed();
} else {
switch (int.parse(widget.type)) { switch (int.parse(widget.type)) {
case 0: case 0:
{ {
// //
return _isSendSuccess return Column(
? sendElectronicKeySucceed()
: Column(
children: [ children: [
keyInfoWidget(), keyInfoWidget(),
keyTimeWidget(), keyTimeWidget(),
@ -99,9 +100,7 @@ class _SendElectronicKeyPageState extends State<SendElectronicKeyPage> {
case 1: case 1:
{ {
// //
return _isSendSuccess return Column(
? sendElectronicKeySucceed()
: Column(
children: [ children: [
keyInfoWidget(), keyInfoWidget(),
remoteUnlockingWidget(), remoteUnlockingWidget(),
@ -113,9 +112,7 @@ class _SendElectronicKeyPageState extends State<SendElectronicKeyPage> {
case 2: case 2:
{ {
// //
return _isSendSuccess return Column(
? sendElectronicKeySucceed()
: Column(
children: [ children: [
keyInfoWidget(), keyInfoWidget(),
remoteUnlockingWidget(), remoteUnlockingWidget(),
@ -127,9 +124,7 @@ class _SendElectronicKeyPageState extends State<SendElectronicKeyPage> {
case 3: case 3:
{ {
// //
return _isSendSuccess return Column(
? sendElectronicKeySucceed()
: Column(
children: [ children: [
keyInfoWidget(), keyInfoWidget(),
keyPeriodValidityWidget(), keyPeriodValidityWidget(),
@ -143,6 +138,7 @@ class _SendElectronicKeyPageState extends State<SendElectronicKeyPage> {
return Container(); return Container();
} }
} }
}
// widget // widget
Widget keyInfoWidget() { Widget keyInfoWidget() {
@ -412,7 +408,7 @@ class _SendElectronicKeyPageState extends State<SendElectronicKeyPage> {
btnName: '完成', btnName: '完成',
onClick: () { onClick: () {
_isSendSuccess = false; _isSendSuccess = false;
setState(() {}); Navigator.pop(context, true);
}), }),
SizedBox( SizedBox(
height: 10.h, height: 10.h,

View File

@ -78,12 +78,17 @@ class _PasswordKeyListPageState extends State<PasswordKeyListPage> {
btnName: TranslationLoader.lanKeys!.getPassword!.tr, btnName: TranslationLoader.lanKeys!.getPassword!.tr,
onClick: () { onClick: () {
Navigator.pushNamed( Navigator.pushNamed(
context, Routers.passwordKeyManagePage, arguments: { context, Routers.passwordKeyManagePage,
arguments: {
"lockMainEntity": lockMainEntity, "lockMainEntity": lockMainEntity,
"keyInfo": keyInfo "keyInfo": keyInfo
}).then((val) {
if (val != null) {
mockNetworkDataRequest();
setState(() {});
}
}); });
}, }),
),
SizedBox( SizedBox(
height: 42.h, height: 42.h,
) )

View File

@ -14,11 +14,12 @@ import '../../../../tools/baseGetXController.dart';
import '../../../../tools/storage.dart'; import '../../../../tools/storage.dart';
class PasswordKeyPerpetualLogic extends BaseGetXController { class PasswordKeyPerpetualLogic extends BaseGetXController {
late DateTime getStartDateTime;
// //
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) async { _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((reply) async {
// //
if (reply is SenderCustomPasswordsReply) { if (reply is SenderCustomPasswordsReply) {
var token = reply.data.sublist(2, 6); var token = reply.data.sublist(2, 6);
@ -39,11 +40,14 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
// //
print("${reply.commandType!.typeValue} 需要鉴权"); print("${reply.commandType!.typeValue} 需要鉴权");
var privateKey = await Storage.getStringList(saveBluePrivateKey); var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
var publicKey = await Storage.getStringList(saveBluePublicKey); var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!); List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
print('得到的开始时间时间戳$getStartDate');
IoSenderManage.senderCustomPasswordsCommand( IoSenderManage.senderCustomPasswordsCommand(
keyID: "1", keyID: "1",
userID: await Storage.getUid(), userID: await Storage.getUid(),
@ -55,8 +59,7 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
needAuthor: 1, needAuthor: 1,
publicKey: publicKeyDataList, publicKey: publicKeyDataList,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
token: token token: token);
);
break; break;
case 0x07: case 0x07:
// //
@ -78,9 +81,15 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
}); });
} }
void getStartDate(DateTime startDate) {
getStartDateTime = startDate;
}
// //
Future<void> senderCustomPasswords() async { Future<void> senderCustomPasswords() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async { BlueManage().judgeReconnect(
BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName,
(DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) { if (state == DeviceConnectionState.connected) {
var publicKey = await Storage.getStringList(saveBluePublicKey); var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!); List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
@ -103,8 +112,7 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
needAuthor: 1, needAuthor: 1,
publicKey: publicKeyDataList, publicKey: publicKeyDataList,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
token: getTokenList token: getTokenList);
);
} }
}); });
} }
@ -121,7 +129,6 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
void onInit() { void onInit() {
// TODO: implement onInit // TODO: implement onInit
super.onInit(); super.onInit();
} }
@override @override
@ -129,5 +136,4 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
// TODO: implement onClose // TODO: implement onClose
_replySubscription.cancel(); _replySubscription.cancel();
} }
} }

View File

@ -6,6 +6,7 @@ import 'package:flutter_pickers/style/default_style.dart';
import 'package:flutter_pickers/time_picker/model/date_mode.dart'; import 'package:flutter_pickers/time_picker/model/date_mode.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart';
import 'package:star_lock/main/lockMian/entity/lockInfoEntity.dart'; import 'package:star_lock/main/lockMian/entity/lockInfoEntity.dart';
import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/baseGetXController.dart';
@ -33,7 +34,10 @@ class PasswordKeyPerpetualPage extends StatefulWidget {
} }
class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> { class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
final TextEditingController _controller = TextEditingController(); final TextEditingController _nameController = TextEditingController();
final TextEditingController _pwdController = TextEditingController();
final logic = Get.put(PasswordKeyPerpetualLogic());
late bool _isSendSuccess; // late bool _isSendSuccess; //
late bool _isPermanent; // late bool _isPermanent; //
late String _getPwdStr; late String _getPwdStr;
@ -47,7 +51,9 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return indexChangeWidget(); return SingleChildScrollView(
child: indexChangeWidget(),
);
} }
@override @override
@ -85,7 +91,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip1!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip1!.tr)
], ],
); );
@ -99,7 +105,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip2!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip2!.tr)
], ],
); );
@ -112,7 +118,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip3!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip3!.tr)
], ],
); );
@ -127,9 +133,9 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
perpetualKeyWidget(TranslationLoader.lanKeys!.password!.tr, perpetualKeyWidget(TranslationLoader.lanKeys!.password!.tr,
"请输入6-9位数字", _controller), "请输入6-9位数字", _pwdController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip4!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip4!.tr)
], ],
); );
@ -143,7 +149,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip5!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip5!.tr)
], ],
); );
@ -156,7 +162,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip6!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip6!.tr)
], ],
); );
@ -179,7 +185,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
leftTitel: titleStr, leftTitel: titleStr,
rightTitle: "", rightTitle: "",
isHaveRightWidget: true, isHaveRightWidget: true,
rightWidget: getTFWidget(rightTitle)), rightWidget: getTFWidget(rightTitle, controller)),
), ),
SizedBox(height: 10.h), SizedBox(height: 10.h),
], ],
@ -346,6 +352,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
SubmitBtn( SubmitBtn(
btnName: TranslationLoader.lanKeys!.getPassword!.tr, btnName: TranslationLoader.lanKeys!.getPassword!.tr,
onClick: () { onClick: () {
logic.getStartDate(_effectiveDateTime);
getKeyboardPwdRequest(); getKeyboardPwdRequest();
}), }),
], ],
@ -403,7 +410,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
var entity = await ApiRepository.to.getPasswordKey( var entity = await ApiRepository.to.getPasswordKey(
getFailureDateTime, getFailureDateTime,
'0', '0',
_controller.text, _nameController.text,
getKeyType, getKeyType,
'0', '0',
lockId, lockId,
@ -466,7 +473,8 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
SubmitBtn( SubmitBtn(
btnName: '完成', btnName: '完成',
onClick: () { onClick: () {
Navigator.pop(context); _isSendSuccess = false;
Navigator.pop(context, true);
}), }),
SizedBox( SizedBox(
height: 10.h, height: 10.h,
@ -489,7 +497,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
} }
// //
Widget getTFWidget(String tfStr) { Widget getTFWidget(String tfStr, TextEditingController editController) {
return SizedBox( return SizedBox(
height: 50.h, height: 50.h,
width: 300.w, width: 300.w,
@ -499,7 +507,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
child: TextField( child: TextField(
// //
maxLines: 1, maxLines: 1,
controller: _controller, controller: editController,
autofocus: false, autofocus: false,
textAlign: TextAlign.end, textAlign: TextAlign.end,
decoration: InputDecoration( decoration: InputDecoration(