app-starlock/lib/main/lockMian/lockList/lockList_page.dart

324 lines
12 KiB
Dart
Executable File

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart';
import 'package:star_lock/main/lockMian/lockList/lockList_state.dart';
import '../../../appRouters.dart';
import '../../../app_settings/app_colors.dart';
import '../../../common/XSConstantMacro/XSConstantMacro.dart';
import '../../../tools/appRouteObserver.dart';
import '../../../tools/dateTool.dart';
import '../entity/lockListInfo_entity.dart';
import 'lockListGroup_view.dart';
import 'lockList_logic.dart';
class LockListPage extends StatefulWidget {
const LockListPage({required this.lockListInfoGroupEntity, Key? key})
: super(key: key);
final LockListInfoGroupEntity lockListInfoGroupEntity;
@override
State<LockListPage> createState() => _LockListPageState();
}
class _LockListPageState extends State<LockListPage> with RouteAware {
late LockListLogic logic;
late LockListState state;
@override
void initState() {
super.initState();
logic = Get.put(LockListLogic(widget.lockListInfoGroupEntity));
state = Get.find<LockListLogic>().state;
}
@override
Widget build(BuildContext context) {
return GetBuilder<LockListLogic>(builder: (LockListLogic logic) {
return Scaffold(
body: ListView.separated(
itemCount: logic.groupDataList.length,
itemBuilder: (BuildContext context, int index) {
final GroupList itemData = logic.groupDataList[index];
return _buildLockExpandedList(context, index, itemData);
},
shrinkWrap: true,
physics: const AlwaysScrollableScrollPhysics(),
separatorBuilder: (BuildContext context, int index) {
return const Divider(
height: 1,
color: AppColors.greyLineColor,
);
}),
);
});
}
//设备多层级列表
Widget _buildLockExpandedList(
BuildContext context, int index, GroupList itemData) {
final List<LockListInfoItemEntity> lockItemList =
itemData.lockList ?? <LockListInfoItemEntity>[];
return LockListGroupView(
onTap: () {
//是否选中组
if (itemData.isChecked) {
} else {}
setState(() {});
},
typeImgList: const <dynamic>[],
groupItem: itemData,
child: ListView.separated(
itemCount: lockItemList.length,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
separatorBuilder: (BuildContext context, int index) {
return const Divider(height: 1, color: AppColors.greyLineColor);
},
itemBuilder: (BuildContext c, int index) {
final LockListInfoItemEntity keyInfo = lockItemList[index];
bool isLast = false;
if (lockItemList.length == index + 1) {
isLast = true;
}
return Slidable(
key: ValueKey<int?>(keyInfo.keyId),
endActionPane: ActionPane(
extentRatio: 0.2,
motion: const ScrollMotion(),
children: <Widget>[
SlidableAction(
onPressed: (BuildContext context) {
state.lockListInfoItemEntity = keyInfo;
logic.deleyLockLogicOfRoles();
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
label: '删除'.tr,
padding: EdgeInsets.only(left: 5.w, right: 5.w),
),
],
),
child: lockInfoListItem(keyInfo, isLast, () {
if ((keyInfo.keyType == XSConstantMacro.keyTypeTime ||
keyInfo.keyType == XSConstantMacro.keyTypeLoop) &&
(keyInfo.keyStatus ==
XSConstantMacro.keyStatusWaitIneffective)) {
logic.showToast('您的钥匙未生效'.tr);
return;
}
if ((keyInfo.keyType == XSConstantMacro.keyTypeTime ||
keyInfo.keyType == XSConstantMacro.keyTypeLong ||
keyInfo.keyType == XSConstantMacro.keyTypeLoop) &&
(keyInfo.keyStatus == XSConstantMacro.keyStatusFrozen)) {
logic.showToast('您的钥匙已冻结'.tr);
return;
}
if ((keyInfo.keyType == XSConstantMacro.keyTypeTime ||
keyInfo.keyType == XSConstantMacro.keyTypeLoop) &&
(keyInfo.keyStatus == XSConstantMacro.keyStatusExpired)) {
logic.showToast('您的钥匙已过期'.tr);
return;
}
Get.toNamed(Routers.lockDetailMainPage,
arguments: <String, Object>{
// "lockMainEntity": widget.lockMainEntity,
'keyInfo': keyInfo,
'isOnlyOneData': false,
});
}),
);
}),
);
}
Widget lockInfoListItem(
LockListInfoItemEntity keyInfo, bool isLast, Function() action) {
return GestureDetector(
onTap: action,
child: Container(
// height: 122.h,
margin: isLast
? EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w, bottom: 20.w)
: EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w),
decoration: BoxDecoration(
color: (((keyInfo.keyType == XSConstantMacro.keyTypeTime ||
keyInfo.keyType == XSConstantMacro.keyTypeLoop) &&
(keyInfo.keyStatus ==
XSConstantMacro.keyStatusWaitIneffective ||
keyInfo.keyStatus ==
XSConstantMacro.keyStatusFrozen ||
keyInfo.keyStatus ==
XSConstantMacro.keyStatusExpired)) ||
(keyInfo.keyType == XSConstantMacro.keyTypeLong &&
keyInfo.keyStatus == XSConstantMacro.keyStatusFrozen))
? AppColors.greyBackgroundColor
: Colors.white,
borderRadius: BorderRadius.circular(20.w),
),
child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 20.h,
),
Row(
children: <Widget>[
SizedBox(width: 30.w),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
keyInfo.lockAlias!,
style: TextStyle(
fontSize: 24.sp,
fontWeight: FontWeight.w500,
color: keyInfo.passageMode == 1
? AppColors.openPassageModeColor
: AppColors.darkGrayTextColor),
),
],
),
),
SizedBox(width: 20.w),
Image.asset(
logic.showElectricIcon(keyInfo.electricQuantity!),
width: 30.w,
height: 24.w,
),
SizedBox(width: 2.w),
Text(
'${keyInfo.electricQuantity!}%',
style: TextStyle(
fontSize: 18.sp, color: AppColors.darkGrayTextColor),
),
SizedBox(width: 30.w),
],
),
SizedBox(height: 5.h),
Visibility(
visible: keyInfo.passageMode == 1,
child: Row(
children: <Widget>[
SizedBox(width: 30.w),
Container(
padding: EdgeInsets.only(right: 5.w, left: 5.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.w),
color: AppColors.openPassageModeColor,
),
child: Text('常开模式开启'.tr,
style: TextStyle(
fontSize: 18.sp,
color: AppColors.appBarIconColor)),
),
],
)),
SizedBox(height: 5.h),
Visibility(
visible: keyInfo.lockSetting!.remoteUnlock == 1,
child: Row(
children: <Widget>[
SizedBox(width: 30.w),
Text(
'远程开锁'.tr,
style: TextStyle(
fontSize: 18.sp, color: AppColors.darkGrayTextColor),
),
],
)),
SizedBox(height: 20.h),
Visibility(
visible: logic.getShowType(keyInfo),
child: Row(
children: <Widget>[
SizedBox(width: 30.w),
Container(
padding: EdgeInsets.only(right: 5.w, left: 5.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.w),
color:
DateTool().compareTimeIsOvertime(keyInfo.endDate!)
? AppColors.listTimeYellowColor
: AppColors.mainColor,
),
child: Text(logic.getKeyEffective(keyInfo),
style: TextStyle(fontSize: 18.sp, color: Colors.white)
// child: Text(logic.compareTimeIsOvertime(keyInfo.endDate!) ? "已过期" : "余${logic.compareTimeGetDaysFromNow(keyInfo.endDate!)}天", style: TextStyle(fontSize: 18.sp, color: Colors.white)
),
),
],
)),
SizedBox(height: 5.h),
Row(
children: <Widget>[
SizedBox(width: 30.w),
Text(
"${logic.getUseKeyTypeStr(keyInfo.startDate, keyInfo.endDate, keyInfo.keyType)}/${keyInfo.isLockOwner == 1 ? '超级管理员'.tr : (keyInfo.keyRight == 1 ? "授权管理员".tr : "普通用户".tr)}",
style: TextStyle(
fontSize: 18.sp, color: AppColors.darkGrayTextColor),
),
],
),
SizedBox(height: 20.h),
],
),
),
);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
/// 路由订阅
AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!);
}
@override
void dispose() {
/// 取消路由订阅
AppRouteObserver().routeObserver.unsubscribe(this);
super.dispose();
}
/// 从上级界面进入 当前界面即将出现
@override
void didPush() {
super.didPush();
state.ifCurrentScreen.value = true;
}
/// 返回上一个界面 当前界面即将消失
@override
void didPop() {
super.didPop();
logic.cancelBlueConnetctToastTimer();
// BlueManage().stopScan();
state.ifCurrentScreen.value = false;
}
/// 从下级返回 当前界面即将出现
@override
void didPopNext() {
super.didPopNext();
state.ifCurrentScreen.value = true;
}
/// 进入下级界面 当前界面即将消失
@override
void didPushNext() {
super.didPushNext();
logic.cancelBlueConnetctToastTimer();
// BlueManage().stopScan();
state.ifCurrentScreen.value = false;
}
}