import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.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_tool.dart'; import '../../../tools/storage.dart'; import '../../../tools/toast.dart'; import '../../../translations/trans_lib.dart'; import '../../lockMian/entity/lockListInfo_entity.dart'; import 'lockDetail_logic.dart'; class LockDetailPage extends StatefulWidget { final bool isFrist; final LockListInfoItemEntity lockListInfoItemEntity; const LockDetailPage( {Key? key, required this.isFrist, required this.lockListInfoItemEntity}) : super(key: key); @override State createState() => _LockDetailPageState(); } class _LockDetailPageState extends State with TickerProviderStateMixin, RouteAware { // with RouteAware final logic = Get.put(LockDetailLogic()); final state = Get.find().state; static const methodChannel = MethodChannel('talkPlugin'); @override void initState() { // TODO: implement initState super.initState(); state.keyInfos.value = widget.lockListInfoItemEntity; state.lockUserNo = state.keyInfos.value.lockUserNo!; state.senderUserId = state.keyInfos.value.senderUserId!; state.isAttendance.value = state.keyInfos.value.lockSetting!.attendance!; state.isOpenLockNeedOnline.value = state.keyInfos.value.lockSetting!.appUnlockOnline!; state.electricQuantity.value = state.keyInfos.value.electricQuantity!; BlueManage().connectDeviceName = state.keyInfos.value.bluetooth!.bluetoothDeviceName!; // BlueManage().connectDeviceMacAddress = // state.keyInfos.value.bluetooth!.bluetoothDeviceId!; List publicKeyData = state.keyInfos.value.bluetooth!.publicKey!.cast(); var saveStrList = changeIntListToStringList(publicKeyData); Storage.setStringList(saveBluePublicKey, saveStrList); // 私钥 List privateKeyData = state.keyInfos.value.bluetooth!.privateKey!.cast(); var savePrivateKeyList = changeIntListToStringList(privateKeyData); Storage.setStringList(saveBluePrivateKey, savePrivateKeyList); // signKey List signKeyData = state.keyInfos.value.bluetooth!.signKey!.cast(); var saveSignKeyList = changeIntListToStringList(signKeyData); Storage.setStringList(saveBlueSignKey, saveSignKeyList); // logic.startScanAction(); listeningAnimations(); } @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: Obx(() => bottomWidget())) ], ), ); } Widget topWidget() { // KeyInfos keyInfo = widget.lockMainEntity.data!.keyInfos![0]; return Column( children: [ SizedBox(height: 50.h), Stack( alignment: Alignment.center, children: [ SizedBox( width: 1.sw - 120.w * 2, child: Center( child: Text(widget.lockListInfoItemEntity.lockAlias!, style: TextStyle(fontSize: 22.sp, fontWeight: FontWeight.w400), ))), Positioned( child: Obx(() => Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Text("${state.electricQuantity.value}%", style: TextStyle(fontSize: 18.sp, color: AppColors.darkGrayTextColor)), SizedBox(width: 2.w), Image.asset(showElectricIcon(state.electricQuantity.value), width: 30.w, height: 24.w), SizedBox(width: 30.w), ], )) ) ], ), SizedBox(height: 30.h), Container( // width: 1.sw, color: Colors.white, height: 330.w, child: Stack( children: [ Center( child: GestureDetector( child: Obx(() => Stack( children: [ Image.asset( state.lockState.value == 4 ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png', width: 330.w, height: 330.w, ), (state.lockState.value == 1 || state.lockState.value == 3) ? buildRotationTransition() : Positioned( child: Image.asset( 'images/main/icon_main_openLockBtn_circle.png', width: 330.w, height: 330.w, )), ], )), onTap: () { logic.startConnect(); }, )), ], ), ), SizedBox( height: 30.h, ), // Row( // mainAxisAlignment: MainAxisAlignment.center, // children: [ // Text( // '门已上锁', // style: TextStyle( // fontSize: 26.sp, // color: Colors.black, // fontWeight: FontWeight.w500), // ), // ], // ), // SizedBox( // height: 6.h, // ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( TranslationLoader.lanKeys!.clickUnlockAndHoldDownClose!.tr, style: TextStyle( fontSize: 22.sp, color: AppColors.btnDisableColor, fontWeight: FontWeight.w500), ), ], ), SizedBox( height: 30.h, ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( 'images/icon_electronicKey_admin.png', width: 24.w, height: 20.w, color: AppColors.mainColor, //应根据状态显示(当前角色为超级管理员 应显示蓝色图标) ), SizedBox( width: 6.w, ), Text( state.keyInfos.value.isLockOwner == 1 ? TranslationLoader.lanKeys!.superAdmin!.tr : (state.keyInfos.value.keyRight == 1 ? TranslationLoader.lanKeys!.authorizedAdmin!.tr: TranslationLoader.lanKeys!.normalUser!.tr), style: TextStyle( fontSize: 20.sp, color: AppColors.darkGrayTextColor), ), SizedBox( width: 80.w, ), Image.asset( state.keyInfos.value.remoteEnable == 1 ? 'images/main/icon_main_remoteUnlocking.png' : 'images/main/icon_main_remoteUnlocking_grey.png', width: 24.w, height: 20.w, // color: state.keyInfos.value.remoteEnable == 1 // ? AppColors.btnDisableColor // : AppColors.mainColor, ), SizedBox( width: 6.w, ), Text( TranslationLoader.lanKeys!.gatewayDevice!.tr, style: TextStyle( fontSize: 20.sp, color: state.keyInfos.value.remoteEnable == 1 ? AppColors.mainColor : AppColors.btnDisableColor), ), ], ), SizedBox( height: 20.h, ), Divider( height: 1, color: AppColors.greyLineColor, indent: 20.w, endIndent: 20.w, ) ], ); } //旋转动画 Widget buildRotationTransition() { return Positioned( child: RotationTransition( //设置动画的旋转中心 alignment: Alignment.center, //动画控制器 turns: state.animationController, //将要执行动画的子view child: Image.asset( 'images/main/icon_main_openLockBtn_circle.png', width: 330.w, height: 330.w, ), ), ); } Widget bottomWidget() { return Container( margin: EdgeInsets.only(left: 10.w, right: 10.w, top: 40.h), // color: Colors.blue, child: GridView.count( crossAxisCount: 4, // childAspectRatio: 3, crossAxisSpacing: 20.w, mainAxisSpacing: 0.h, physics: const NeverScrollableScrollPhysics(), children: getBottomWidget()), ); } // 根据权限显示不同的底部按钮 List getBottomWidget(){ if(state.keyInfos.value.isLockOwner == 1 || state.keyInfos.value.keyRight == 1){ // 超级管理员、授权管理员 return getAllWidget(); }else{ return getNormalWidget(); } } // 普通用户 List getNormalWidget() { var showWidgetArr = [ // 操作记录 bottomItem('images/main/icon_main_operatingRecord.png', TranslationLoader.lanKeys!.operatingRecord!.tr, () { Get.toNamed(Routers.lockOperatingRecordPage, arguments: {"keyInfo": widget.lockListInfoItemEntity}); }), // 设置 bottomItem('images/main/icon_main_set.png', TranslationLoader.lanKeys!.set!.tr, () { BlueManage().stopScan(); Get.toNamed(Routers.lockSetPage, arguments: {"lockId": widget.lockListInfoItemEntity.lockId}); }), ]; return showWidgetArr; } // 授权管理员、超级管理员字段 List getAllWidget() { var showWidgetArr = []; // 考勤 if (state.isAttendance.value == 1) { showWidgetArr.add(bottomItem('images/main/icon_main_clockingIn.png', TranslationLoader.lanKeys!.checkingIn!.tr, () { Get.toNamed(Routers.checkingInListPage, arguments: state.keyInfos.value); })); } // 电子钥匙 showWidgetArr.add(bottomItem('images/main/icon_main_electronicKey.png', TranslationLoader.lanKeys!.electronicKey!.tr, () { Get.toNamed(Routers.electronicKeyListPage, arguments: {"keyInfo": widget.lockListInfoItemEntity}); })); // 密码 showWidgetArr.add(bottomItem('images/main/icon_main_password.png', TranslationLoader.lanKeys!.password!.tr, () { Get.toNamed(Routers.passwordKeyListPage, arguments: {"keyInfo": widget.lockListInfoItemEntity}); })); // ic卡 if (state.keyInfos.value.lockFeature!.icCard == 1) { showWidgetArr.add(bottomItem('images/main/icon_main_icCard.png', TranslationLoader.lanKeys!.card!.tr, () { Get.toNamed(Routers.cardListPage, arguments: { "lockId": widget.lockListInfoItemEntity.lockId, }); })); } // 指纹 if (state.keyInfos.value.lockFeature!.fingerprint == 1) { showWidgetArr.add(bottomItem('images/main/icon_main_fingerprint.png', TranslationLoader.lanKeys!.fingerprint!.tr, () { Get.toNamed(Routers.fingerprintListPage, arguments: { "lockId": widget.lockListInfoItemEntity.lockId, }); })); } // 遥控 if (state.keyInfos.value.lockFeature!.bluetoothRemoteControl == 1) { showWidgetArr.add(bottomItem('images/main/icon_main_remoteControl.png', TranslationLoader.lanKeys!.remoteControl!.tr, () { Get.toNamed(Routers.remoteControlListPage); })); } //可视对讲门锁新增->人脸 if (state.keyInfos.value.lockFeature!.d3Face == 1) { showWidgetArr.add( bottomItem('images/main/icon_face.png', TranslationLoader.lanKeys!.humanFace!.tr, () { Get.toNamed(Routers.faceList, arguments: { "lockId": widget.lockListInfoItemEntity.lockId, }); // Toast.show(msg: "功能暂未开放"); // tokNative('videoTalk', // arguments: {'videoTalk': 'videoTalk'}).then((result) { // print('$result'); // }); }), ); } //可视对讲门锁新增->监控 if (state.keyInfos.value.lockFeature!.videoIntercom == 1) { showWidgetArr.add( bottomItem('images/main/icon_catEyes.png', TranslationLoader.lanKeys!.monitoring!.tr, () { // Navigator.pushNamed(context, Routers.otherTypeKeyListPage, // arguments: 1); // Toast.show(msg: "功能暂未开放"); Get.toNamed(Routers.lockMonitoringPage, arguments: { "lockId": widget.lockListInfoItemEntity.lockId }); }), ); } var endWiddget = [ // 授权管理员 bottomItem('images/main/icon_main_authorizedAdmin.png', TranslationLoader.lanKeys!.authorizedAdmin!.tr, () { Get.toNamed(Routers.authorizedAdminListPage, arguments: {"keyInfo": widget.lockListInfoItemEntity}); }), // 操作记录 bottomItem('images/main/icon_main_operatingRecord.png', TranslationLoader.lanKeys!.operatingRecord!.tr, () { Get.toNamed(Routers.lockOperatingRecordPage, arguments: {"keyInfo": widget.lockListInfoItemEntity}); }), // 视频日志 bottomItem('images/main/icon_lockDetail_videoLog.png', TranslationLoader.lanKeys!.videoLog!.tr, () { //视频日志 Get.toNamed(Routers.videoLogPage); }), // 消息提醒 bottomItem('images/main/icon_lockDetail_messageReminding.png', TranslationLoader.lanKeys!.messageReminding!.tr, () { Get.toNamed(Routers.msgNotificationPage); }), // 设置 bottomItem('images/main/icon_main_set.png', TranslationLoader.lanKeys!.set!.tr, () { BlueManage().stopScan(); Get.toNamed(Routers.lockSetPage, arguments: {"lockId": widget.lockListInfoItemEntity.lockId}); }), ]; 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)) ], )), ); } listeningAnimations() { Future.delayed(Duration.zero, () { state.animationController = AnimationController( duration: const Duration(seconds: 20), vsync: this); state.animationController.repeat(); //动画开始、结束、向前移动或向后移动时会调用StatusListener state.animationController.addStatusListener((status) { print("AnimationStatus:$status"); if (status == AnimationStatus.completed) { state.animationController.forward(); } else if (status == AnimationStatus.dismissed) { state.animationController.forward(); } }); }); } String showElectricIcon (int electricnumber){ if(electricnumber >= 100){ return 'images/main/icon_lockElectricLevel_5.png'; }else if((electricnumber > 50) && (electricnumber < 100)){ return 'images/main/icon_lockElectricLevel_4.png'; }else if((electricnumber > 25) && (electricnumber <= 50)){ return 'images/main/icon_lockElectricLevel_3.png'; }else if((electricnumber > 5) && (electricnumber <= 25)){ return 'images/main/icon_lockElectricLevel_2.png'; }else if(electricnumber <= 5){ return 'images/main/icon_lockElectricLevel_1.png'; } return 'images/main/icon_lockElectricLevel_5.png'; } static Future tokNative(String method, {required Map arguments}) async { if (arguments == null) { return await methodChannel.invokeMethod(method); } else { return await methodChannel.invokeMethod(method, arguments); } } @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); state.animationController.dispose(); super.dispose(); BlueManage().stopScan(); BlueManage().disconnect(BlueManage().connectDeviceMacAddress); } /// @override void didPush() { print("LockDetailPage didPush"); } /// Called when the current route has been popped off. @override void didPop() { print("LockDetailPage didPop"); } /// Called when the current route has been popped off. @override void didPopNext() { print("LockDetailPage didPopNext"); } /// Called when the current route has been popped off. @override void didPushNext() { print("LockDetailPage didPushNext"); } }