import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import '../../../../../appRouters.dart'; import '../../../../../app_settings/app_colors.dart'; import '../../../../../tools/titleAppBar.dart'; import '../../../../../translations/trans_lib.dart'; import '../../../../tools/EasyRefreshTool.dart'; import '../../../../tools/keySearchWidget.dart'; import '../../../../tools/noData.dart'; import 'transferSmartLock_entity.dart'; import 'transferSmartLock_logic.dart'; class TransferSmartLockPage extends StatefulWidget { const TransferSmartLockPage({Key? key}) : super(key: key); @override State createState() => _TransferSmartLockPageState(); } class _TransferSmartLockPageState extends State { final logic = Get.put(TransferSmartLockLogic()); final state = Get.find().state; Future getHttpData() async { logic.getTransferLockListData().then((TransferSmartLockEntity value){ setState(() {}); }); } @override void initState() { super.initState(); getHttpData(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: TranslationLoader.lanKeys!.selectiveLock!.tr, haveBack: true, backgroundColor: AppColors.mainColor, actionsList: [ TextButton( onPressed: () { setState(() { if(state.isSelectAll == true){ for (var element in state.transferSmartLockListData.value) { state.isSelectAll = false; element.select = 0; } }else{ for (var element in state.transferSmartLockListData.value) { state.isSelectAll = true; element.select = 1; } } }); }, child: Text(state.isSelectAll == true ? TranslationLoader.lanKeys!.cancel!.tr : TranslationLoader.lanKeys!.checkAll!.tr, style: TextStyle(color: Colors.white, fontSize: 24.sp))) ], ), body: EasyRefreshTool( onRefresh: (){ getHttpData(); }, child: Obx(() => state.transferSmartLockListData.value.isNotEmpty ? Column( children: [ // KeySearchWidget( // editingController: state.searchController, // onSubmittedAction: () { // getHttpData(); // }, // ), SizedBox(height: 10.h), Expanded(child: _buildMainUI()), SizedBox(height: 20.h), _buildNextBtn(), SizedBox(height: 64.h) ], ): NoData()), ), ); } Widget _buildMainUI() { return ListView.separated( itemCount: state.transferSmartLockListData.value.length, separatorBuilder: (context, index) { return Divider( height: 1, indent: 20.w, endIndent: 20.w, color: AppColors.greyLineColor, ); }, itemBuilder: (c, index) { TransferSmartLockItemData transferSmartLockItemData = state.transferSmartLockListData.value[index]; return _electronicKeyItem(transferSmartLockItemData, () { setState(() { if(transferSmartLockItemData.select == 1){ transferSmartLockItemData.select = 0; }else{ transferSmartLockItemData.select = 1; } }); }); }); } Widget _electronicKeyItem(TransferSmartLockItemData transferSmartLockItemData, Function() action) { return GestureDetector( onTap: action, child: Container( color: Colors.white, height: 90.h, child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox(width: 20.w), Image.asset((transferSmartLockItemData.select == 1) ? 'images/icon_round_select.png' : 'images/icon_round_unSelect.png', width: 30.w, height: 30.w), SizedBox(width: 16.w), Image.asset('images/icon_lockGroup_item.png', width: 50.h, height: 50.h, fit: BoxFit.fill), SizedBox(width: 10.w), Text(transferSmartLockItemData.lockAlias!, style: TextStyle(fontSize: 22.sp, color: AppColors.blackColor)) ], ), ), ); } Widget _buildNextBtn() { return GestureDetector( child: Container( color: AppColors.mainColor, width: ScreenUtil().screenWidth, height: 64.h, child: TextButton( onPressed: () async { bool isCanNext = false; var idList = []; for (var element in state.transferSmartLockListData.value) { if(element.select == 1){ isCanNext = true; idList.add(element.lockId); } } if(isCanNext == false){ logic.showToast("请选择锁".tr); return; } var data = await Get.toNamed(Routers.recipientInformationPage, arguments: { "idList":idList, "isFromType":1, }); if(data != null) { logic.getTransferLockListData(); } }, child: Text('下一步', style: TextStyle(fontSize: 28.sp, color: Colors.white), )), ), ); } }