252 lines
8.6 KiB
Dart
Executable File
252 lines
8.6 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendLockGroupListEntity.dart';
|
||
import 'package:star_lock/tools/showTipView.dart';
|
||
|
||
import '../../../../../../appRouters.dart';
|
||
import '../../../../../../app_settings/app_colors.dart';
|
||
import '../../../../../../tools/commonItem.dart';
|
||
import '../../../../../../tools/titleAppBar.dart';
|
||
import '../../../../../../translations/trans_lib.dart';
|
||
import '../../../../tools/left_slide_actions.dart';
|
||
import '../../../../tools/noData.dart';
|
||
import '../../../../tools/showIosTipView.dart';
|
||
import 'lockGroupList_logic.dart';
|
||
|
||
class LockGroupListPage extends StatefulWidget {
|
||
const LockGroupListPage({Key? key}) : super(key: key);
|
||
|
||
@override
|
||
State<LockGroupListPage> createState() => _LockGroupListPageState();
|
||
}
|
||
|
||
class _LockGroupListPageState extends State<LockGroupListPage> {
|
||
final logic = Get.put(LockGroupListLogic());
|
||
final state = Get.find<LockGroupListLogic>().state;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
backgroundColor: AppColors.mainBackgroundColor,
|
||
appBar: TitleAppBar(
|
||
barTitle: TranslationLoader.lanKeys!.lockGroup!.tr,
|
||
haveBack: true,
|
||
actionsList: [
|
||
IconButton(
|
||
icon: Image.asset(
|
||
'images/icon_add_white.png',
|
||
width: 36.w,
|
||
height: 36.w,
|
||
),
|
||
onPressed: () {
|
||
// 处理操作按钮的点击事件-添加锁分组
|
||
state.changeNameController.text = "";
|
||
// showCupertinoAlertDialog(context, true, 0);
|
||
ShowTipView().showTFViewAlertDialog(
|
||
state.changeNameController,
|
||
TranslationLoader.lanKeys!.createNewGroup!.tr,
|
||
TranslationLoader.lanKeys!.pleaseEnter!.tr, () {
|
||
//发送编辑钥匙名称请求
|
||
if (state.changeNameController.text.isNotEmpty) {
|
||
Navigator.of(context).pop();
|
||
logic.addLockGroupRequest();
|
||
} else {
|
||
logic.showToast(
|
||
TranslationLoader.lanKeys!.pleaseEnterAGroupName!.tr);
|
||
}
|
||
});
|
||
},
|
||
),
|
||
],
|
||
backgroundColor: AppColors.mainColor),
|
||
body: Column(
|
||
children: [
|
||
Expanded(
|
||
child: Obx(() => state.itemDataList.value.isEmpty
|
||
? NoData()
|
||
: _buildMainUI())),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildMainUI() {
|
||
for (int i = 0; i < state.itemDataList.value.length; i++) {
|
||
GroupListItem itemData = state.itemDataList.value[i];
|
||
state.lockNum += itemData.lockList!.length;
|
||
}
|
||
return ListView.separated(
|
||
itemCount: state.itemDataList.value.length + 1,
|
||
itemBuilder: (c, index) {
|
||
if (index == state.itemDataList.value.length) {
|
||
return Center(
|
||
child: Column(
|
||
children: [
|
||
SizedBox(
|
||
height: 20.h,
|
||
),
|
||
SizedBox(
|
||
height: 40.h,
|
||
child: Text(
|
||
'${TranslationLoader.lanKeys!.lockTrCount!.tr}:${state.lockNum.toString()}',
|
||
style: TextStyle(
|
||
color: AppColors.darkGrayTextColor, fontSize: 20.sp),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
);
|
||
} else {
|
||
GroupListItem itemData = state.itemDataList.value[index];
|
||
if (itemData.groupType == 0) {
|
||
state.ungrouped = itemData;
|
||
}
|
||
if (index < state.itemDataList.value.length) {
|
||
return LeftSlideActions(
|
||
key: Key(itemData.keyGroupId!.toString()),
|
||
actionsWidth: itemData.groupType != 0 ? 200.w : 0,
|
||
actions: itemData.groupType != 0
|
||
? [
|
||
_buildEditBtn(itemData),
|
||
_buildDeleteBtn(itemData),
|
||
]
|
||
: [],
|
||
decoration: const BoxDecoration(
|
||
borderRadius: BorderRadius.all(Radius.circular(1)),
|
||
),
|
||
child: CommonItem(
|
||
leftTitel:
|
||
'${itemData.keyGroupName}(${itemData.lockList?.length})',
|
||
rightTitle: "",
|
||
allHeight: 70.h,
|
||
action: () {
|
||
Get.toNamed(Routers.lockItemListPage, arguments: {
|
||
'groupListItem': itemData,
|
||
"ungrouped": state.ungrouped
|
||
});
|
||
}),
|
||
);
|
||
}
|
||
return const SizedBox.shrink();
|
||
}
|
||
},
|
||
separatorBuilder: (BuildContext context, int index) {
|
||
return const Divider(
|
||
height: 1,
|
||
color: AppColors.greyLineColor,
|
||
);
|
||
});
|
||
}
|
||
|
||
// void showCupertinoAlertDialog(BuildContext context, bool isAdd, int groupId) {
|
||
// showDialog(
|
||
// context: context,
|
||
// builder: (BuildContext context) {
|
||
// return ShowTFView(
|
||
// title: isAdd ? TranslationLoader.lanKeys!.createNewGroup!.tr : "修改名称",
|
||
// tipTitle: TranslationLoader.lanKeys!.pleaseEnter!.tr,
|
||
// controller: state.changeNameController,
|
||
// sureClick: () {
|
||
// //发送编辑钥匙名称请求
|
||
// if (state.changeNameController.text.isNotEmpty) {
|
||
// if(isAdd == true){
|
||
// logic.addLockGroupRequest();
|
||
// }else{
|
||
// logic.editLockGroupRequest(groupId);
|
||
// }
|
||
// Get.back();
|
||
// } else {
|
||
// logic.showToast(TranslationLoader.lanKeys!.pleaseEnterAGroupName!.tr);
|
||
// }
|
||
// },
|
||
// cancelClick: () {
|
||
// Get.back();
|
||
// },
|
||
// );
|
||
// },
|
||
// );
|
||
// }
|
||
|
||
Widget _buildDeleteBtn(GroupListItem groupListItem) {
|
||
return GestureDetector(
|
||
onTap: () {
|
||
// 省略: 弹出是否删除的确认对话框。
|
||
// showIosTipViewDialog(context, groupListItem);
|
||
ShowTipView().showIosTipWithContentDialog("分组下的锁将被移到未分组里".tr, () {
|
||
logic.deleteLockGroupRequest(groupListItem.keyGroupId!);
|
||
});
|
||
},
|
||
child: Container(
|
||
width: 100.w,
|
||
color: const Color(0xFFF20101),
|
||
alignment: Alignment.center,
|
||
child: Text(
|
||
TranslationLoader.lanKeys!.delete!.tr,
|
||
style: const TextStyle(
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.w500,
|
||
color: Colors.white,
|
||
height: 1,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildEditBtn(GroupListItem groupListItem) {
|
||
return GestureDetector(
|
||
onTap: () {
|
||
// 编辑
|
||
state.changeNameController.text = groupListItem.keyGroupName!;
|
||
// showCupertinoAlertDialog(context, false, groupListItem.keyGroupId!);
|
||
|
||
ShowTipView().showTFViewAlertDialog(
|
||
state.changeNameController,
|
||
TranslationLoader.lanKeys!.createNewGroup!.tr,
|
||
TranslationLoader.lanKeys!.pleaseEnter!.tr, () {
|
||
if (state.changeNameController.text.isNotEmpty) {
|
||
logic.editLockGroupRequest(groupListItem.keyGroupId!);
|
||
} else {
|
||
logic.showToast(
|
||
TranslationLoader.lanKeys!.pleaseEnterAGroupName!.tr);
|
||
}
|
||
});
|
||
},
|
||
child: Container(
|
||
width: 100.w,
|
||
color: AppColors.mainColor,
|
||
alignment: Alignment.center,
|
||
child: Text(
|
||
"重命名".tr,
|
||
style: const TextStyle(
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.w500,
|
||
color: Colors.white,
|
||
height: 1,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
// void showIosTipViewDialog(BuildContext context, GroupListItem groupListItem) {
|
||
// showDialog(
|
||
// context: context,
|
||
// builder: (BuildContext context) {
|
||
// return ShowIosTipView(
|
||
// title: TranslationLoader.lanKeys!.hint!.tr,
|
||
// tipTitle: "分组下的锁将被移到未分组里",
|
||
// sureClick: () {
|
||
// Get.back();
|
||
// logic.deleteLockGroupRequest(groupListItem.keyGroupId!);
|
||
// },
|
||
// cancelClick: () {
|
||
// Get.back();
|
||
// },
|
||
// );
|
||
// }
|
||
// );
|
||
// }
|
||
}
|