app-starlock/lib/main/lockDetail/lockDetail/lockDetail_page.dart

1570 lines
56 KiB
Dart
Executable File

import 'dart:async';
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:intl/intl.dart' as intl;
import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/flavors.dart';
import 'package:star_lock/main/lockDetail/lockDetail/device_network_info.dart';
import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
import 'package:star_lock/main/lockMian/lockMain/lockMain_logic.dart';
import 'package:star_lock/mine/gateway/addGateway/gatewayConfigurationWifi/getGatewayConfiguration_entity.dart';
import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
import 'package:star_lock/tools/aliyunRealNameAuth/aliyunRealNameAuthHandle.dart';
import 'package:star_lock/tools/baseGetXController.dart';
import 'package:star_lock/tools/bugly/bugly_tool.dart';
import 'package:star_lock/tools/showCupertinoAlertView.dart';
import 'package:star_lock/tools/showTipView.dart';
import 'package:star_lock/tools/storage.dart';
import 'package:star_lock/widget/flavors_img.dart';
import '../../../appRouters.dart';
import '../../../app_settings/app_settings.dart';
import '../../../blue/blue_manage.dart';
import '../../../common/XSConstantMacro/XSConstantMacro.dart';
import '../../../tools/appRouteObserver.dart';
import '../../../tools/dateTool.dart';
import '../../../tools/eventBusEventManage.dart';
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;
@override
State<LockDetailPage> createState() => _LockDetailPageState();
}
class _LockDetailPageState extends State<LockDetailPage>
with TickerProviderStateMixin, RouteAware {
// with RouteAware
final LockDetailLogic logic = Get.put(LockDetailLogic());
final LockDetailState state = Get.find<LockDetailLogic>().state;
@override
void initState() {
super.initState();
state.animationController =
AnimationController(duration: const Duration(seconds: 1), vsync: this);
state.animationController!.repeat();
//动画开始、结束、向前移动或向后移动时会调用StatusListener
state.animationController!.addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.completed) {
state.animationController!.reset();
state.animationController!.forward();
} else if (status == AnimationStatus.dismissed) {
state.animationController!.reset();
state.animationController!.forward();
}
});
state.pageController.addListener(() {
state.currentPage.value = state.pageController.page!.round();
});
_initRefreshLockDetailInfoDataEventAction();
logic.initReplySubscription();
logic.initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction();
logic.loadData(
lockListInfoItemEntity: widget.lockListInfoItemEntity,
isOnlyOneData: widget.isOnlyOneData);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
/// 路由订阅
AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!);
state.isOpenLockNeedOnline.refresh();
}
StreamSubscription? _lockRefreshLockDetailInfoDataEvent;
void _initRefreshLockDetailInfoDataEventAction() {
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
_lockRefreshLockDetailInfoDataEvent = eventBus
.on<RefreshLockDetailInfoDataEvent>()
.listen((RefreshLockDetailInfoDataEvent event) {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return F.sw(skyCall: skWidget, xhjCall: xhjWidget);
}
//鑫泓佳布局
Widget xhjWidget() {
final bool isShowTip = (state.keyInfos.value.keyType ==
XSConstantMacro.keyTypeTime ||
state.keyInfos.value.keyType == XSConstantMacro.keyTypeLoop) &&
(DateTool().compareTimeGetDaysFromNow(state.keyInfos.value.endDate!) <=
15 &&
DateTool()
.compareTimeGetDaysFromNow(state.keyInfos.value.endDate!) >=
0) &&
(state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusNormalUse ||
state.keyInfos.value.keyStatus ==
XSConstantMacro.keyStatusWaitReceive);
return Scaffold(
backgroundColor: Colors.white,
body: Obx(() {
final String lockAlias = state.keyInfos.value.lockAlias!;
return Stack(
children: <Widget>[
SingleChildScrollView(
child: Column(
children: <Widget>[
Visibility(
visible: isShowTip,
child: Container(
// height: 30.h,
width: 1.sw,
color: const Color(0xFFFBEFD4),
padding: EdgeInsets.only(top: 8.h, bottom: 8.h),
child: Text(
"${"钥匙将在".tr}${DateTool().compareTimeGetDaysFromNow(state.keyInfos.value.endDate!)}${"天后失效".tr}",
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xffCBA74B), fontSize: 24.sp)),
),
),
SizedBox(height: 10.h),
Padding(
padding: EdgeInsets.symmetric(horizontal: 24.w),
child: Text(
lockAlias,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 24.sp, color: Colors.black),
),
),
SizedBox(
height: 20.h,
),
xhjInfoView(),
SizedBox(
height: 20.h,
),
labelText(
img: 'images/icon_slider_horizontal.png',
text: '功能'.tr,
child: bottomWidget()),
btnText(
img: 'images/main/icon_main_set.png',
text: '设置'.tr,
onTap: () {
if (state.openDoorBtnisUneable.value == false) {
return;
}
Get.toNamed(Routers.lockSetPage,
arguments: <String, Object?>{
'lockId': state.keyInfos.value.lockId,
'isOnlyOneData': state.isOnlyOneData
});
}),
if (!F.isProductionEnv)
labelText(
img: 'images/icon_puzzlepiece_extension.png',
text: '配件'.tr,
child: attachmentWidget()),
],
),
),
Visibility(
visible: state.iSClosedUnlockSuccessfulPopup.value,
// visible: true,
child: Container(
width: 1.sw,
height: 1.sh - ScreenUtil().statusBarHeight * 2,
color: Colors.black.withOpacity(0.3),
child: _unlockSuccessWidget()),
)
],
);
}),
);
}
Widget btnText(
{required String img, required String text, required var onTap}) {
return GestureDetector(
onTap: onTap,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 0.05.sw, vertical: 15.h),
padding: EdgeInsets.symmetric(horizontal: 0.05.sw, vertical: 30.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16.r),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black.withOpacity(0.15),
offset: const Offset(0, 0),
blurRadius: 5.r,
spreadRadius: 0,
),
]),
child: Row(
children: <Widget>[
FlavorsImg(
black: true,
child: Image.asset(
img,
width: 32.r,
height: 32.r,
),
),
SizedBox(
width: 15.w,
),
Text(
text,
style: TextStyle(fontSize: 24.sp, color: AppColors.blackColor),
),
const Spacer(),
Icon(
Icons.arrow_forward_ios_rounded,
size: 18.r,
)
],
),
),
);
}
Widget labelText(
{required String img, required String text, required Widget child}) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 0.05.sw, vertical: 15.h),
padding: EdgeInsets.symmetric(horizontal: 0.05.sw, vertical: 15.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16.r),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black.withOpacity(0.15),
offset: const Offset(0, 0),
blurRadius: 5.r,
spreadRadius: 0,
),
]),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Image.asset(
img,
width: 32.r,
height: 32.r,
),
SizedBox(
width: 15.w,
),
Text(
text,
style: TextStyle(fontSize: 24.sp, color: AppColors.blackColor),
),
],
),
SizedBox(
height: 18.h,
),
child,
],
),
);
}
Widget xhjInfoView() {
return Container(
width: 0.9.sw,
height: 0.6.sw,
constraints: BoxConstraints(
minHeight: 0.6.sw,
),
decoration: BoxDecoration(
image: const DecorationImage(
image: AssetImage('images/xhj_main_bg.jpg'),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(20.r),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black.withOpacity(0.15),
offset: const Offset(0, 0),
blurRadius: 10.r,
spreadRadius: 0,
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 10.h),
GestureDetector(
onTap: () {
ShowTipView().showSureAlertDialog(
"${"锁电量更新时间".tr}:${state.keyInfos.value.electricQuantityDate! != 0 ? DateTool().dateToYMDHNString(state.keyInfos.value.electricQuantityDate!.toString()) : "-"}");
},
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Image.asset(showElectricIcon(state.electricQuantity.value),
width: 30.w, height: 24.w),
SizedBox(width: 2.w),
Text('${state.electricQuantity.value}%',
style: TextStyle(
fontSize: 18.sp,
color: AppColors.darkGrayTextColor)),
SizedBox(width: 2.w),
Icon(
Icons.info, // 使用内置的 warning 图标,它是一个叹号
color: AppColors.mainColor, // 设置图标颜色为红色
size: 25.w, // 设置图标大小为 30
),
SizedBox(width: 20.w),
],
),
Visibility(
visible: state
.keyInfos.value.lockFeature!.isSupportBackupBattery ==
1,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlavorsImg(
child: Image.asset(
showElectricIcon(
state.electricQuantityStandby.value),
width: 30.w,
height: 24.w),
),
SizedBox(width: 2.w),
Text('${state.electricQuantityStandby.value}%',
style: TextStyle(
fontSize: 18.sp,
color: AppColors.darkGrayTextColor)),
SizedBox(width: 2.w),
FlavorsImg(
child: Icon(
Icons.info, // 使用内置的 warning 图标,它是一个叹号
color: AppColors.mainColor, // 设置图标颜色为红色
size: 25.w, // 设置图标大小为 30
),
),
SizedBox(width: 20.w),
],
),
)
],
),
),
Container(
height: 200.r,
child: Stack(
children: [
Center(
child: GestureDetector(
onTap: () {
if (state.openDoorBtnisUneable.value == true) {
logic.functionBlocker
.block(isNeedRealNameAuthThenOpenLock);
}
},
onLongPressStart: (LongPressStartDetails details) {
if (state.openDoorBtnisUneable.value == true) {
void callback() {
setState(startUnLock);
}
logic.functionBlocker.block(callback);
}
},
child: Container(
width: 200.r,
height: 200.r,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100.w),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black.withOpacity(0.3),
offset: const Offset(0, 0),
blurRadius: 15.r,
spreadRadius: 0,
),
]),
child: Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
if (state.openDoorBtnisUneable.value == false)
Icon(
Icons.bluetooth_searching,
size: 78.r,
color: AppColors.mainColor.withOpacity(0.6),
)
else
Image.asset(
state.isOpenPassageMode.value == 1
? 'images/icon_lock_err.png'
: 'images/icon_lock_fill.png',
width: 68.r,
height: 68.r,
color: AppColors.mainColor,
),
if (state.openLockBtnState.value == 1)
xhjBuildRotationTransition(
width: 168.r,
height: 168.r,
)
else
Positioned(
child: Image.asset(
'images/icon_circle_dotted.png',
width: 168.r,
height: 168.r,
color: state.openDoorBtnisUneable.value == false
? AppColors.mainColor.withOpacity(0.6)
: state.isOpenPassageMode.value == 1
? Colors.red
: AppColors.mainColor,
)),
],
),
),
),
),
Positioned(
right: 90.w,
bottom: 1,
child: Obx(() => Visibility(
visible:
state.keyInfos.value.lockSetting!.remoteUnlock == 1,
child: GestureDetector(
onTap: () {
ShowCupertinoAlertView().isToRemoteUnLockAlert(
remoteUnlockAction: () {
if (state.keyInfos.value.hasGateway != 1) {
logic.showToast('附近没有可用网关'.tr);
}
logic.remoteOpenLock();
});
},
child: Align(
alignment: const Alignment(0.6, 1),
child: FlavorsImg(
child: Image.asset(
'images/main/icon_main_remoteUnlocking_xhj.png',
width: 50.w,
height: 52.w,
),
)),
))),
)
],
),
),
// SizedBox(height: 15.h),
Expanded(
child: Center(
child: Text(
'点击开锁,长按闭锁'.tr,
textAlign: TextAlign.center,
style: TextStyle(
color: AppColors.darkGrayTextColor,
fontSize: 20.sp,
),
),
),
),
adminInfoView(center: true, max: false),
SizedBox(height: 10.h)
],
),
);
}
//斯凯布局
Widget skWidget() {
return ListView(
children: <Widget>[
Visibility(
visible:
(state.keyInfos.value.keyType == XSConstantMacro.keyTypeTime ||
state.keyInfos.value.keyType ==
XSConstantMacro.keyTypeLoop) && // 限时、循环
(DateTool().compareTimeGetDaysFromNow(
state.keyInfos.value.endDate!) <=
15 &&
DateTool().compareTimeGetDaysFromNow(
state.keyInfos.value.endDate!) >=
0) && // 0到30天
(state.keyInfos.value.keyStatus ==
XSConstantMacro.keyStatusNormalUse ||
state.keyInfos.value.keyStatus ==
XSConstantMacro.keyStatusWaitReceive) // 正常使用、待接收
,
child: Container(
// height: 30.h,
width: 1.sw,
color: const Color(0xFFFBEFD4),
padding:
EdgeInsets.only(top: 8.h, bottom: 8.h, right: 10.w, left: 10.h),
child: Text(
"${"钥匙将在".tr}${DateTool().compareTimeGetDaysFromNow(state.keyInfos.value.endDate!)}${"天后失效".tr}",
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
style:
TextStyle(color: const Color(0xffCBA74B), fontSize: 24.sp)),
),
),
Stack(children: <Widget>[
Container(
width: 1.sw,
height: 1.sh - ScreenUtil().statusBarHeight,
color: Colors.white,
child: Column(
children: <Widget>[
topWidget(),
SizedBox(
height: 10.h,
),
Obx(buildPageIndicator),
Expanded(
child: Container(
margin: EdgeInsets.only(left: 10.w, right: 10.w, top: 30.h),
child: PageView(
scrollDirection: Axis.horizontal,
controller: state.pageController,
children: <Widget>[
Obx(bottomWidget),
attachmentWidget(),
],
),
)),
],
),
),
Visibility(
visible: state.iSClosedUnlockSuccessfulPopup.value,
child: Container(
width: 1.sw,
height: 1.sh - ScreenUtil().statusBarHeight * 2,
color: Colors.black.withOpacity(0.3),
child: _unlockSuccessWidget()),
)
]),
],
);
}
Widget topWidget() {
return Column(
children: <Widget>[
F.sw(
skyCall: () => SizedBox(height: 50.h),
xhjCall: () => Padding(
padding: EdgeInsets.only(
top: 12.h,
left: 15.w,
bottom: 16.h,
right: 15.w,
),
child: adminInfoView(center: false),
),
),
Stack(
children: <Widget>[
Center(
child: Text(
state.lockAlias.value,
style: TextStyle(
fontSize: 22.sp,
fontWeight: FontWeight.w400,
color: state.isOpenPassageMode.value == 1
? AppColors.openPassageModeColor
: AppColors.darkGrayTextColor),
)),
Positioned(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GestureDetector(
onTap: () {
ShowTipView().showSureAlertDialog(
"${"电量更新时间:".tr}${DateTool().dateToYMDHNString(state.keyInfos.value.electricQuantityDate!.toString())}");
},
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlavorsImg(
child: Image.asset(
showElectricIcon(state.electricQuantity.value),
width: 30.w,
height: 24.w),
),
SizedBox(width: 2.w),
Text('${state.electricQuantity.value}%',
style: TextStyle(
fontSize: 18.sp,
color: AppColors.darkGrayTextColor)),
SizedBox(width: 2.w),
state.keyInfos.value.network?.isOnline == 1
? Icon(
Icons.wifi,
color: AppColors.mainColor,
size: 22.sp,
)
: SizedBox.shrink(),
SizedBox(width: 4.w),
FlavorsImg(
child: Icon(
Icons.info, // 使用内置的 warning 图标,它是一个叹号
color: AppColors.mainColor, // 设置图标颜色为红色
size: 25.w, // 设置图标大小为 30
),
),
SizedBox(width: 20.w),
],
),
),
Visibility(
visible: state
.keyInfos.value.lockFeature!.isSupportBackupBattery ==
1,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlavorsImg(
child: Image.asset(
showElectricIcon(
state.electricQuantityStandby.value),
width: 30.w,
height: 24.w),
),
SizedBox(width: 2.w),
Text('${state.electricQuantityStandby.value}%',
style: TextStyle(
fontSize: 18.sp,
color: AppColors.darkGrayTextColor)),
SizedBox(width: 2.w),
FlavorsImg(
child: Icon(
Icons.info, // 使用内置的 warning 图标,它是一个叹号
color: AppColors.mainColor, // 设置图标颜色为红色
size: 25.w, // 设置图标大小为 30
),
),
SizedBox(width: 20.w),
],
),
),
],
))
],
),
F.sw(
skyCall: () => SizedBox(height: 30.h),
xhjCall: () => SizedBox(height: 15.h),
),
Container(
// width: 1.sw,
color: Colors.white,
height: 330.w,
child: Stack(
children: <Widget>[
Center(
child: GestureDetector(
onTap: () {
if (state.openDoorBtnisUneable.value == true) {
logic.functionBlocker.block(isNeedRealNameAuthThenOpenLock);
}
},
onLongPressStart: (LongPressStartDetails details) {
if (state.openDoorBtnisUneable.value == true) {
void callback() {
setState(startUnLock);
}
logic.functionBlocker.block(callback);
}
},
child: Stack(
children: <Widget>[
FlavorsImg(
child: Image.asset(
state.openDoorBtnisUneable.value == false
? 'images/main/icon_main_openLockBtn_grey.png'
: (state.isOpenPassageMode.value == 1
? 'images/main/icon_main_normallyOpenMode_center.png'
: 'images/main/icon_main_openLockBtn_center.png'),
width: 330.w,
height: 330.w,
// color: AppColors.primaryTopColor,
),
),
if (state.openDoorBtnisUneable.value == false)
Positioned(
child: FlavorsImg(
child: Image.asset(
'images/main/icon_main_openLockBtn_grey.png',
width: 330.w,
height: 330.w,
),
),
)
else
state.openLockBtnState.value == 1
? buildRotationTransition(
width: 330.w,
height: 330.w,
)
: Positioned(
child: FlavorsImg(
child: Image.asset(
state.isOpenPassageMode.value == 1
? 'images/main/icon_main_normallyOpenMode_circle.png'
: 'images/main/icon_main_openLockBtn_circle.png',
width: 330.w,
height: 330.w,
),
)),
],
),
)),
Positioned(
right: 90.w,
bottom: 1,
child: Obx(() => Visibility(
visible:
state.keyInfos.value.lockSetting!.remoteUnlock == 1,
child: GestureDetector(
onTap: () {
ShowCupertinoAlertView().isToRemoteUnLockAlert(
remoteUnlockAction: () {
if (state.keyInfos.value.hasGateway != 1) {
logic.showToast('附近没有可用网关'.tr);
}
logic.remoteOpenLock();
});
},
child: Align(
alignment: const Alignment(0.6, 1),
child: FlavorsImg(
child: Image.asset(
'images/main/icon_main_remoteUnlocking.png',
width: 50.w,
height: 52.w,
),
)),
))),
)
],
),
),
SizedBox(
height: 30.h,
),
Container(
padding: EdgeInsets.symmetric(horizontal: 20.w),
child: Center(
child: Text(
logic.getKeyStatusTextAndShow(),
maxLines: 2,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.sp,
color: AppColors.btnDisableColor,
fontWeight: FontWeight.w500),
),
),
),
SizedBox(
height: 30.h,
),
F.sw(skyCall: adminInfoView, xhjCall: () => const SizedBox()),
SizedBox(
height: 20.h,
),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
)
],
);
}
Widget adminInfoView({bool center = true, bool max = true}) {
return Row(
mainAxisAlignment:
center ? MainAxisAlignment.center : MainAxisAlignment.start,
children: <Widget>[
Row(
mainAxisSize: max ? MainAxisSize.max : MainAxisSize.min,
children: [
Image.asset(
'images/icon_electronicKey_admin.png',
width: 24.w,
height: 20.w,
color: AppColors.blackColor, //应根据状态显示(当前角色为超级管理员 应显示蓝色图标)
),
SizedBox(width: 6.w),
Text(
state.keyInfos.value.isLockOwner == 1
? '超级管理员英文'.tr
: (state.keyInfos.value.keyRight == 1
? '授权管理员英文'.tr
: '普通用户'.tr),
style: TextStyle(
fontSize: 20.sp, color: AppColors.darkGrayTextColor),
),
SizedBox(width: 40.w),
],
),
Row(
mainAxisSize: max ? MainAxisSize.max : MainAxisSize.min,
children: [
FlavorsImg(
child: Image.asset(
state.keyInfos.value.hasGateway == 1
? 'images/main/icon_main_remoteUnlocking.png'
: 'images/main/icon_main_remoteUnlocking_grey.png',
width: 24.w,
height: 20.w,
),
),
SizedBox(width: 6.w),
Text(
'网关设备英文'.tr,
style: TextStyle(
fontSize: 20.sp,
color: state.keyInfos.value.hasGateway == 1
? AppColors.mainColor
: AppColors.btnDisableColor),
),
SizedBox(width: 20.w),
],
),
Row(
mainAxisSize: max ? MainAxisSize.max : MainAxisSize.min,
children: [
FlavorsImg(
child: Image.asset('images/main/icon_lockDetail_needNetwork.png',
width: 24.w,
height: 20.w,
color: state.isOpenLockNeedOnline.value == 1
? AppColors.mainColor
: AppColors.btnDisableColor),
),
SizedBox(width: 6.w),
Text(
'手机需联网英文'.tr,
style: TextStyle(
fontSize: 20.sp,
color: state.isOpenLockNeedOnline.value == 1
? AppColors.mainColor
: AppColors.btnDisableColor),
),
],
)
],
);
}
//旋转动画
Widget xhjBuildRotationTransition(
{required double width, required double height}) {
return Positioned(
child: RotationTransition(
//设置动画的旋转中心
alignment: Alignment.center,
//动画控制器
turns: state.animationController!,
//将要执行动画的子view
child: Image.asset(
'images/icon_circle_dotted.png',
width: width,
height: height,
color: state.isOpenPassageMode.value == 1
? Colors.red
: AppColors.mainColor,
),
),
);
}
//旋转动画
Widget buildRotationTransition(
{required double width, required double height}) {
return Positioned(
child: RotationTransition(
//设置动画的旋转中心
alignment: Alignment.center,
//动画控制器
turns: state.animationController!,
//将要执行动画的子view
child: FlavorsImg(
child: Image.asset(
state.isOpenPassageMode.value == 1
? 'images/main/icon_main_normallyOpenMode_circle.png'
: 'images/main/icon_main_openLockBtn_circle.png',
width: width,
height: height,
),
),
),
);
}
//圆点指示器
Widget buildPageIndicator() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(2, (int index) {
return Container(
width: 10.0.w,
height: 10.0.w,
margin: EdgeInsets.symmetric(vertical: 10.0.w, horizontal: 6.0.w),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: state.currentPage.value == index
? AppColors.mainColor
: Colors.grey,
),
);
}),
);
}
//配件区域
Widget attachmentWidget() {
return SizedBox(
width: ScreenUtil().screenWidth - 20.w,
child: GridView.count(
crossAxisCount: 4,
// childAspectRatio: 3,
crossAxisSpacing: 0.w,
mainAxisSpacing: 0.h,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: getAttachmentWidget()),
);
}
// 配件配置
List<Widget> getAttachmentWidget() {
final List<Widget> showWidgetArr = <Widget>[];
// 无线键盘
// if (state.isAttendance.value == 1) {
// showWidgetArr.add(bottomItem(
// 'images/main/icon_lockDetail_WirelessKeyboard.png',
// '无线键盘',
// state.bottomBtnisUneable.value,
// () {}));
// }
// // 照明
// showWidgetArr.add(bottomItem('images/main/icon_lockDetail_illuminator.png',
// '照明', state.bottomBtnisUneable.value, () {}));
// // 照明
// showWidgetArr.add(bottomItem('images/main/icon_lockDetail_illuminator.png',
// '门磁', state.bottomBtnisUneable.value, () {}));
// // 门磁
// showWidgetArr.add(bottomItem('images/main/icon_lockDetail_illuminator.png',
// '开门器', state.bottomBtnisUneable.value, () {}));
// 新增配件
showWidgetArr.add(bottomItem('images/main/icon_main_addLock.png', '新增配件'.tr,
state.bottomBtnisEable.value, () {
Navigator.pushNamed(context, Routers.accessoriesListPage);
}));
return showWidgetArr;
}
Widget bottomWidget() {
return SizedBox(
width: ScreenUtil().screenWidth,
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
mainAxisSpacing: 0.h,
crossAxisSpacing: 0.h,
mainAxisExtent: 90.0, // 设置每个 item 的固定高度
),
itemCount: (state.keyInfos.value.isLockOwner == 1 ||
state.keyInfos.value.keyRight == 1)
? getAllWidget().length
: getNormalWidget().length,
itemBuilder: (context, index) {
Widget widget = getBottomWidget()[index];
return widget;
},
// physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
)
// GridView.count(
// crossAxisCount: 4,
// // childAspectRatio: 3,
// crossAxisSpacing: 0.h,
// mainAxisSpacing: 0.h,
// shrinkWrap: true,
// physics: const NeverScrollableScrollPhysics(),
// children: getBottomWidget()),
);
}
// 根据权限显示不同的底部按钮
List<Widget> getBottomWidget() {
if (state.keyInfos.value.isLockOwner == 1 ||
state.keyInfos.value.keyRight == 1) {
// 超级管理员、授权管理员
return getAllWidget();
} else {
return getNormalWidget();
}
}
// 普通用户
List<Widget> getNormalWidget() {
final List<Widget> showWidgetArr = <Widget>[];
// 考勤
// if (state.isAttendance.value == 1) {
// showWidgetArr.add(bottomItem('images/main/icon_main_clockingIn.png',
// '考勤'.tr, state.bottomBtnisEable.value, () {
// Get.toNamed(Routers.checkingInListPage,
// arguments: state.keyInfos.value);
// }));
// }
// 操作记录
showWidgetArr.add(bottomItem('images/main/icon_main_operatingRecord.png',
'操作记录'.tr, state.bottomBtnisEable.value, () {
Get.toNamed(Routers.doorLockLogPage,
arguments: <String, LockListInfoItemEntity>{
'keyInfo': state.keyInfos.value
});
}));
// 设置
if (F.isSKY) {
showWidgetArr
.add(bottomItem('images/main/icon_main_set.png', '设置'.tr, true, () {
Get.toNamed(Routers.lockSetPage, arguments: <String, Object?>{
'lockId': state.keyInfos.value.lockId,
'isOnlyOneData': state.isOnlyOneData
});
}));
}
return showWidgetArr;
}
// 授权管理员、超级管理员字段
List<Widget> getAllWidget() {
final List<Widget> showWidgetArr = <Widget>[];
// 考勤
// if (state.isAttendance.value == 1) {
// showWidgetArr.add(bottomItem('images/main/icon_main_clockingIn.png',
// '考勤'.tr, state.bottomBtnisEable.value, () {
// Get.toNamed(Routers.checkingInListPage,
// arguments: state.keyInfos.value);
// }));
// }
// 电子钥匙
showWidgetArr.add(bottomItem('images/main/icon_main_electronicKey.png',
'电子钥匙'.tr, state.bottomBtnisEable.value, () {
Get.toNamed(Routers.electronicKeyListPage);
}));
// 密码
showWidgetArr.add(bottomItem('images/main/icon_main_password.png', '密码'.tr,
state.bottomBtnisEable.value, () {
Get.toNamed(Routers.passwordKeyListPage,
arguments: <String, LockListInfoItemEntity>{
'keyInfo': state.keyInfos.value
});
}));
// ic卡
if (state.keyInfos.value.lockFeature!.icCard == 1) {
showWidgetArr.add(bottomItem('images/main/icon_main_icCard.png', ''.tr,
state.bottomBtnisEable.value, () {
Get.toNamed(Routers.cardListPage, arguments: <String, int?>{
'lockId': state.keyInfos.value.lockId,
});
}));
}
// 指纹
if (state.keyInfos.value.lockFeature!.fingerprint == 1) {
showWidgetArr.add(bottomItem('images/main/icon_main_fingerprint.png',
'指纹'.tr, state.bottomBtnisEable.value, () {
Get.toNamed(Routers.fingerprintListPage, arguments: <String, int?>{
'lockId': state.keyInfos.value.lockId,
});
}));
}
// 遥控
if (state.keyInfos.value.lockFeature!.bluetoothRemoteControl == 1) {
showWidgetArr.add(bottomItem('images/main/icon_main_remoteControl.png',
'遥控'.tr, state.bottomBtnisEable.value, () {
Get.toNamed(Routers.remoteControlListPage, arguments: <String, int?>{
'lockId': state.keyInfos.value.lockId,
});
}));
}
//可视对讲门锁新增->人脸
if (state.keyInfos.value.lockFeature!.d3Face == 1) {
showWidgetArr.add(
bottomItem(
'images/main/icon_face.png', '人脸'.tr, state.bottomBtnisEable.value,
() {
Get.toNamed(Routers.faceListPage, arguments: <String, int?>{
'lockId': state.keyInfos.value.lockId,
});
}),
);
}
if (state.keyInfos.value.lockFeature!.isSupportIris == 1) {
showWidgetArr.add(
bottomItem(
'images/main/icon_iris.png', '虹膜'.tr, state.bottomBtnisEable.value,
() {
Get.toNamed(Routers.irisListPage, arguments: <String, int?>{
'lockId': state.keyInfos.value.lockId,
});
}),
);
}
if (state.keyInfos.value.lockFeature!.palmVein == 1) {
showWidgetArr.add(
bottomItem(
'images/main/icon_palm.png', '掌静脉'.tr, state.bottomBtnisEable.value,
() {
Get.toNamed(Routers.palmListPage, arguments: <String, int?>{
'lockId': state.keyInfos.value.lockId,
});
}),
);
}
//可视对讲门锁新增->监控
if (state.keyInfos.value.lockFeature!.videoIntercom == 1) {
showWidgetArr.add(
bottomItem('images/main/icon_catEyes.png', '监控'.tr,
state.bottomBtnisEable.value, () async {
logic.sendMonitorMessage();
}),
);
}
// 授权管理员
if (state.keyInfos.value.isLockOwner == 1) {
showWidgetArr.add(bottomItem('images/main/icon_main_authorizedAdmin.png',
'授权管理员'.tr, state.bottomBtnisEable.value, () {
Get.toNamed(Routers.authorizedAdminListPage,
arguments: <String, LockListInfoItemEntity>{
'keyInfo': state.keyInfos.value
});
}));
}
final List<Widget> endWiddget = <Widget>[];
endWiddget.add(
// 操作记录
bottomItem('images/main/icon_main_operatingRecord.png', '操作记录'.tr,
state.bottomBtnisEable.value, () {
// Get.toNamed(Routers.lockOperatingRecordPage,
// arguments: {"keyInfo": state.keyInfos.value});
Get.toNamed(Routers.doorLockLogPage,
arguments: <String, LockListInfoItemEntity>{
'keyInfo': state.keyInfos.value
});
}),
);
if (state.keyInfos.value.lockFeature!.isSupportCatEye == 1) {
//视频日志
endWiddget.add(bottomItem('images/main/icon_lockDetail_videoLog.png',
'视频日志'.tr, state.bottomBtnisEable.value, () {
Get.toNamed(Routers.videoLogPage, arguments: <String, int?>{
'lockId': state.keyInfos.value.lockId,
});
}));
}
if (!F.isProductionEnv) {
endWiddget.add(
// 消息提醒
bottomItem('images/main/icon_lockDetail_messageReminding.png',
'消息提醒'.tr, state.bottomBtnisEable.value, () {
Get.toNamed(Routers.msgNotificationPage, arguments: <String, int?>{
'lockId': state.keyInfos.value.lockId,
'isSupportCatEye':
state.keyInfos.value.lockFeature!.isSupportCatEye,
});
}),
);
}
if (F.isSKY) {
endWiddget.add(
// 设置
bottomItem('images/main/icon_main_set.png', '设置'.tr, true, () {
// logic.clickItemBtnAction(10);
Get.toNamed(Routers.lockSetPage, arguments: <String, Object?>{
'lockId': state.keyInfos.value.lockId,
'isOnlyOneData': state.isOnlyOneData,
});
}),
);
}
showWidgetArr.addAll(endWiddget);
return showWidgetArr;
}
Widget bottomItem(
String iconUrl, String name, bool bottomBtnisEable, Function() onClick) {
final Widget child = F.sw(
skyCall: () => Container(
color: Colors.white,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 42.w,
height: 42.h,
child: Image.asset(iconUrl,
width: 42.w,
height: 42.w,
color: bottomBtnisEable
? AppColors.mainColor
: AppColors.lockDetailBottomBtnUneable,
fit: BoxFit.fitWidth),
),
SizedBox(height: 5.h),
Expanded(
child: Text(name,
style: TextStyle(
fontSize: 20.sp,
color: bottomBtnisEable
? AppColors.blackColor
: AppColors.lockDetailBottomBtnUneable),
textAlign: TextAlign.center))
],
),
),
xhjCall: () => Container(
color: Colors.white,
padding: EdgeInsets.only(left: 3.w, right: 3.w, bottom: 5.h),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
width: 42.w,
height: 42.w,
child: Image.asset(iconUrl,
width: 42.w,
height: 42.w,
color: bottomBtnisEable
? AppColors.mainColor
: AppColors.lockDetailBottomBtnUneable,
fit: BoxFit.fitWidth),
),
SizedBox(height: 15.h),
Text(
name,
// '哈水电费垃圾啊货到付款垃圾啊是老大开发机哈吉手打',
textAlign: TextAlign.center,
maxLines: 4,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 20.sp,
height: 1.0,
color: bottomBtnisEable
? AppColors.blackColor
: AppColors.lockDetailBottomBtnUneable),
),
],
),
));
return GestureDetector(
onTap: bottomBtnisEable
? onClick
: () {
logic.showToast('钥匙不可用'.tr);
},
child: child,
);
}
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';
}
Widget _unlockSuccessWidget() {
String lockAlias = state.keyInfos.value.lockAlias!;
final TextStyle lockAliasTextStyle =
TextStyle(color: AppColors.placeholderTextColor, fontSize: 24.sp);
final TextPainter textPainter = TextPainter(
text: TextSpan(text: lockAlias, style: lockAliasTextStyle),
maxLines: 1,
textDirection: TextDirection.ltr)
..layout(minWidth: 0, maxWidth: double.infinity);
final double textSizeWidth = textPainter.size.width; // 获取文本的尺寸
if (textSizeWidth > 358.w * 2 - 20) {
lockAlias =
'${lockAlias.substring(0, lockAlias.length > 25 ? 25 : lockAlias.length)}...';
}
return Center(
child: Stack(
children: <Widget>[
Image.asset(
'images/main/icon_lockDetail_openLock_succeed.png',
width: 358.w,
height: 348.h,
),
Positioned(
top: 120.h,
width: 358.w,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(state.iSOpenLock.value == true ? '已开锁'.tr : '已闭锁'.tr,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: AppColors.mainColor,
fontSize: 32.sp,
fontWeight: FontWeight.w600)),
SizedBox(
height: 10.h,
),
Text(
lockAlias,
style: TextStyle(
color: AppColors.placeholderTextColor, fontSize: 24.sp),
maxLines: 2,
),
SizedBox(
height: 10.h,
),
Text(
getCurrentFormattedTime(),
style: TextStyle(
color: AppColors.darkGrayTextColor, fontSize: 24.sp),
)
],
)),
Positioned(
top: 288.h,
left: 155.w,
child: GestureDetector(
onTap: () {
state.closedUnlockSuccessfulTimer?.cancel();
setState(() {
state.iSClosedUnlockSuccessfulPopup.value = false;
});
},
child: Container(
width: 60.r,
height: 60.r,
color: Colors.transparent,
)),
),
],
),
);
}
String getCurrentFormattedTime() {
// 获取当前时间
final DateTime now = DateTime.now();
// 格式化日期和时间
final String formattedTime = intl.DateFormat('MM/dd HH:mm').format(now);
return formattedTime;
}
//如果需要实名认证,需认证完成,方可开锁
Future<void> isNeedRealNameAuthThenOpenLock() async {
final bool isNetWork = await LockMainLogic.to()?.judgeTheNetwork() ?? false;
final bool isOpenLockNeedOnline = state.isOpenLockNeedOnline.value == 0;
if (!isOpenLockNeedOnline && !isNetWork) {
return;
}
state.nextAuthTime.value = state.keyInfos.value.nextFaceValidateTime ?? 0;
if (state.keyInfos.value.faceAuthentication == 1 &&
state.nextAuthTime.value > 0 &&
DateTool().compareTimeIsOvertime(state.nextAuthTime.value) == true) {
AliyunRealNameAuthProvider(
getLockInfo: state.keyInfos.value,
onCertifyResultWithTime: (bool isSuccess, int getNextAuthTime) {
state.nextAuthTime.value = getNextAuthTime;
if (isSuccess) {
// 认证成功,去开锁
setState(startOpenLock);
}
}).initAliyunRealNameAuth();
} else {
//无需认证,直接开锁
setState(startOpenLock);
}
}
void startOpenLock() {
if (state.openLockBtnState.value == 1) {
return;
}
// final bool isNetWork = await LockMainLogic.to()?.judgeTheNetwork() ?? false;
final bool isOpenLockNeedOnline = state.isOpenLockNeedOnline.value == 0;
// if (!isOpenLockNeedOnline && !isNetWork) {
// return;
// }
state.iSOpenLock.value = true;
state.openLockBtnState.value = 1;
state.animationController!.forward();
// AppLog.log('点击开锁');
if (isOpenLockNeedOnline) {
// 不需要联网
state.openDoorModel = 0;
// AppLog.log('点击开锁 state.openDoorModel = 0 不需要联网');
// FlutterBuglyPlugin.reportException(exceptionName: '点击了不需要联网开锁');
BuglyTool.uploadException(
message: '点击了不需要联网开锁',
detail: '点击了不需要联网开锁 openDoorModel:${state.openDoorModel}',
upload: false,
begin: true);
AppLog.log('点击开锁 state.openDoorModel = 0 不需要联网');
logic.openDoorAction();
} else {
// 需要联网
state.openDoorModel = 2;
// AppLog.log('点击开锁 state.openDoorModel = 2 需要联网');
// FlutterBuglyPlugin.reportException(exceptionName: '点击了需要联网开锁');
BuglyTool.uploadException(
message: '点击了需要联网开锁',
detail: '点击了需要联网开锁 openDoorModel:${state.openDoorModel}',
upload: false,
begin: true);
AppLog.log('点击开锁 state.openDoorModel = 2 需要联网');
logic.getLockNetToken();
}
}
void startUnLock() {
if (state.openLockBtnState.value == 1) {
return;
}
state.iSOpenLock.value = false;
state.openLockBtnState.value = 1;
state.animationController!.forward();
EasyLoading.showToast('正在尝试闭锁……'.tr, duration: 1000.milliseconds);
AppLog.log('长按闭锁');
if (state.isOpenLockNeedOnline.value == 0) {
// 不需要联网
// AppLog.log('长按闭锁 state.openDoorModel = 32 不需要联网');
state.openDoorModel = 32;
logic.openDoorAction();
} else {
// 需要联网
// AppLog.log('长按闭锁 state.openDoorModel = 34 需要联网');
state.openDoorModel = 34;
logic.getLockNetToken();
}
}
@override
void dispose() {
/// 取消路由订阅
AppRouteObserver().routeObserver.unsubscribe(this);
state.closedUnlockSuccessfulTimer?.cancel();
_lockRefreshLockDetailInfoDataEvent?.cancel();
state.replySubscription.cancel();
state.lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent
?.cancel();
state.LockSetChangeSetRefreshLockDetailWithTypeSubscription?.cancel();
if (state.animationController != null) {
state.animationController!.dispose();
state.animationController = null;
}
super.dispose();
}
/// 从上级界面进入 当前界面即将出现
@override
void didPush() {
super.didPush();
state.ifCurrentScreen.value = true;
}
/// 返回上一个界面 当前界面即将消失
@override
void didPop() {
super.didPop();
state.ifCurrentScreen.value = false;
logic.cancelBlueConnetctToastTimer();
BlueManage().disconnect();
state.openLockBtnState.value = 0;
}
/// 从下级返回 当前界面即将出现
@override
void didPopNext() {
super.didPopNext();
state.ifCurrentScreen.value = true;
}
/// 进入下级界面 当前界面即将消失
@override
void didPushNext() {
super.didPushNext();
state.ifCurrentScreen.value = false;
logic.closeLuckStatus();
BlueManage().disconnect();
}
}