2023-09-18 09:29:33 +08:00

352 lines
11 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get.dart';
import '../../../appRouters.dart';
import '../../../app_settings/app_colors.dart';
import '../../../blue/blue_manage.dart';
import '../../../blue/io_tool/io_manager.dart';
import '../../../blue/io_tool/io_tool.dart';
import '../../../tools/appRouteObserver.dart';
import '../../../tools/storage.dart';
import '../../../translations/trans_lib.dart';
import '../../lockMian/entity/lockInfoEntity.dart';
import 'lockDetail_logic.dart';
class LockDetailPage extends StatefulWidget {
final isFrist;
final KeyInfos keyInfo;
final LockMainEntity lockMainEntity;
const LockDetailPage(
{Key? key,
required this.lockMainEntity,
required this.isFrist,
required this.keyInfo})
: super(key: key);
@override
State<LockDetailPage> createState() => _LockDetailPageState();
}
class _LockDetailPageState extends State<LockDetailPage> with RouteAware {
final logic = Get.put(LockDetailLogic());
final state = Get.find<LockDetailLogic>().state;
@override
void initState() {
// TODO: implement initState
super.initState();
state.keyInfos.value = widget.keyInfo;
BlueManage().connectDeviceName =
state.keyInfos.value.bluetooth!.bluetoothDeviceName!;
BlueManage().connectDeviceMacAddress =
state.keyInfos.value.bluetooth!.bluetoothDeviceId!;
List<int> publicKeyData =
state.keyInfos.value.bluetooth!.publicKey!.cast<int>();
var saveStrList = changeIntListToStringList(publicKeyData);
Storage.setStringList(saveBluePublicKey, saveStrList);
// 私钥
List<int> privateKeyData =
state.keyInfos.value.bluetooth!.privateKey!.cast<int>();
var savePrivateKeyList = changeIntListToStringList(privateKeyData);
Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
// signKey
List<int> signKeyData =
state.keyInfos.value.bluetooth!.signKey!.cast<int>();
var saveSignKeyList = changeIntListToStringList(signKeyData);
Storage.setStringList(saveBlueSignKey, saveSignKeyList);
// print("publicKeyData:$publicKeyData saveStrList:$saveStrList privateKeyData:$privateKeyData savePrivateKeyList:$savePrivateKeyList");
// logic.connectBlue();
}
@override
Widget build(BuildContext context) {
return Container(
width: 1.sw,
height: 1.sh - ScreenUtil().statusBarHeight * 2,
color: Colors.white,
child: Column(
children: [topWidget(), Expanded(child: bottomWidget())],
),
);
}
Widget topWidget() {
// KeyInfos keyInfo = widget.lockMainEntity.data!.keyInfos![0];
return Column(
children: [
SizedBox(height: 30.h),
Stack(
alignment: Alignment.centerRight,
children: [
Align(
alignment: Alignment.center,
child: Text(
widget.keyInfo!.lockAlias!,
style:
TextStyle(fontSize: 22.sp, fontWeight: FontWeight.w400),
)),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
"100%",
style: TextStyle(
fontSize: 18.sp, color: AppColors.darkGrayTextColor),
),
SizedBox(width: 2.w),
Image.asset(
'images/main/icon_main_cell.png',
width: 30.w,
height: 24.w,
),
SizedBox(width: 30.w),
],
),
],
),
SizedBox(height: 30.h),
Container(
// width: 1.sw,
color: Colors.white,
height: 280.w,
child: Stack(
children: [
Center(
child: GestureDetector(
onTap: () {
// logic.transferPermissionsAction();
logic.openDoorAction();
// logic.editLockUserAction();
// logic.factoryDataResetAction();
},
child: Image.asset('images/main/icon_main_openLockBtn.png',
width: 268.w, height: 268.w),
)),
Visibility(
visible:
state.keyInfos.value.remoteEnable == 1 ? true : false,
child: Align(
alignment: const Alignment(0.6, 1),
child: Image.asset(
'images/main/icon_main_remoteUnlocking.png',
width: 50.w,
height: 52.w,
))),
],
),
),
SizedBox(
height: 30.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
TranslationLoader.lanKeys!.clickUnlockAndHoldDownClose!.tr,
style: TextStyle(
fontSize: 20.sp,
color: const Color(0xFFB3B3B3),
fontWeight: FontWeight.w500),
),
],
),
SizedBox(
height: 30.h,
),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
)
],
);
}
Widget bottomWidget() {
return Container(
margin: EdgeInsets.only(left: 10.w, right: 10.w, top: 40.h),
// color: Colors.blue,
child: SizedBox(
child: GridView.count(
crossAxisCount: 4,
// childAspectRatio: 3,
crossAxisSpacing: 20.w,
mainAxisSpacing: 0.h,
physics: const NeverScrollableScrollPhysics(),
children: getShowWidget()),
),
);
}
List<Widget> getShowWidget() {
var showWidgetArr = <Widget>[];
// 考勤
if (state.keyInfos.value.isAttendance == 1) {
showWidgetArr.add(bottomItem('images/main/icon_main_clockingIn.png',
TranslationLoader.lanKeys!.checkingIn!.tr, () {
Get.toNamed(Routers.checkingInListPage,
arguments: state.keyInfos.value);
}));
}
var defaultWidgetArr = [
// 电子钥匙
bottomItem('images/main/icon_main_electronicKey.png',
TranslationLoader.lanKeys!.electronicKey!.tr, () {
Get.toNamed(Routers.electronicKeyListPage, arguments: {
"lockMainEntity": widget.lockMainEntity,
"keyInfo": widget.keyInfo
});
}),
// 密码
bottomItem('images/main/icon_main_password.png',
TranslationLoader.lanKeys!.password!.tr, () {
Get.toNamed(Routers.passwordKeyListPage, arguments: {
"lockMainEntity": widget.lockMainEntity,
"keyInfo": widget.keyInfo
});
}),
// ic卡
bottomItem('images/main/icon_main_icCard.png', TranslationLoader.lanKeys!.card!.tr, () {
Get.toNamed(Routers.otherTypeKeyListPage, arguments: {
"lockId": widget.keyInfo.lockId,
"fromType": 0
});
}),
// 指纹
bottomItem('images/main/icon_main_fingerprint.png', TranslationLoader.lanKeys!.fingerprint!.tr, () {
Get.toNamed(Routers.otherTypeKeyListPage, arguments: {
"lockId": widget.keyInfo.lockId,
"fromType": 1
});
}),
// 遥控
bottomItem('images/main/icon_main_remoteControl.png', TranslationLoader.lanKeys!.remoteControl!.tr, () {
Get.toNamed(Routers.otherTypeKeyListPage, arguments: {
"lockId": widget.keyInfo.lockId,
"fromType": 2
});
}),
];
showWidgetArr.addAll(defaultWidgetArr);
//可视对讲门锁新增->人脸
showWidgetArr.add(
bottomItem('images/main/icon_face.png', '人脸', () {
// Navigator.pushNamed(context, Routers.otherTypeKeyListPage,
// arguments: 1);
}),
);
//可视对讲门锁新增->监控
showWidgetArr.add(
bottomItem('images/main/icon_catEyes.png', '监控', () {
// Navigator.pushNamed(context, Routers.otherTypeKeyListPage,
// arguments: 1);
}),
);
var endWiddget = [
// 授权管理员
bottomItem('images/main/icon_main_authorizedAdmin.png',
TranslationLoader.lanKeys!.authorizedAdmin!.tr, () {
Get.toNamed(Routers.authorizedAdminListPage, arguments: {
"lockMainEntity": widget.lockMainEntity,
"keyInfo": widget.keyInfo
});
}),
// 操作记录
bottomItem('images/main/icon_main_operatingRecord.png',
TranslationLoader.lanKeys!.operatingRecord!.tr, () {
Get.toNamed(Routers.lockOperatingRecordPage, arguments: {
"lockMainEntity": widget.lockMainEntity,
"keyInfo": widget.keyInfo
});
}),
// 设置
bottomItem(
'images/main/icon_main_set.png', TranslationLoader.lanKeys!.set!.tr,
() {
Get.toNamed(Routers.lockSetPage, arguments: widget.keyInfo);
}),
];
showWidgetArr.addAll(endWiddget);
return showWidgetArr;
}
Widget bottomItem(String iconUrl, String name, Function() onClick) {
var width = 42.w;
var height = 42.h;
return GestureDetector(
onTap: onClick,
child: Container(
// height: 300.h,
color: Colors.white,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: width,
height: height,
child: Image.asset(iconUrl,
width: width, height: height, fit: BoxFit.fitWidth),
),
SizedBox(height: 10.w),
Expanded(
child: Text(name,
style: TextStyle(
fontSize: 20.sp, color: AppColors.blackColor),
textAlign: TextAlign.center))
],
)),
);
}
@override
void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies();
/// 路由订阅
AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!);
}
@override
void dispose() {
// TODO: implement dispose
/// 取消路由订阅
AppRouteObserver().routeObserver.unsubscribe(this);
super.dispose();
}
///
@override
void didPush() {}
/// Called when the current route has been popped off.
@override
void didPop() {}
/// Called when the current route has been popped off.
@override
void didPopNext() {}
/// Called when the current route has been popped off.
@override
void didPushNext() {}
}