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/noData.dart'; import 'selectGetewayList_entity.dart'; import 'selectGetewayList_logic.dart'; class SelectGetewayListPage extends StatefulWidget { const SelectGetewayListPage({Key? key}) : super(key: key); @override State createState() => _SelectGetewayListPageState(); } class _SelectGetewayListPageState extends State { final logic = Get.put(SelectGetewayListLogic()); final state = Get.find().state; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: TranslationLoader.lanKeys!.selectGateway!.tr, haveBack: true, backgroundColor: AppColors.mainColor, actionsList: [ TextButton( onPressed: () { setState(() { for (var element in state.getewayListData.value) { if(state.isSelectAll == true){ state.isSelectAll = false; element.select = 0; }else{ state.isSelectAll = true; element.select = 1; } } }); }, child: Text( '全选', style: TextStyle(color: Colors.white, fontSize: 24.sp), )) ], ), body: Column( children: [ Expanded(child: _buildMainUI()), SizedBox( height: 20.h, ), _buildNextBtn(), SizedBox( height: 64.h, ) ], ), ); } Widget _buildMainUI() { return Obx(() => state.getewayListData.value.isNotEmpty ? ListView.separated( itemCount: state.getewayListData.value.length, separatorBuilder: (context, index) { return Divider( height: 1, indent: 20.w, endIndent: 20.w, color: AppColors.greyLineColor, ); }, itemBuilder: (c, index) { GetewayItemData getewayItemData = state.getewayListData.value[index]; return _electronicKeyItem(getewayItemData, () { setState(() { if(getewayItemData.select == 1){ getewayItemData.select = 0; }else{ getewayItemData.select = 1; } }); }); }): NoData()); } Widget _electronicKeyItem(GetewayItemData getewayItemData, Function() action) { return GestureDetector( onTap: action, child: Container( color: Colors.white, height: 80.h, child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox( width: 20.w, ), GestureDetector( child: Image.asset( (getewayItemData.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/getewayType_G2.png', width: 50.w, height: 50.w, fit: BoxFit.fill, ), SizedBox( width: 16.w, ), Text(getewayItemData.plugName!, style: TextStyle(fontSize: 24.sp),) ], ), ), ); } 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.getewayListData.value) { if(element.select == 1){ isCanNext = true; idList.add(element.plugId); } } if(isCanNext == false){ logic.showToast("请选择锁".tr); return; } var data = await Get.toNamed(Routers.recipientInformationPage, arguments: { "idList":idList, "isFromType":2, }); if(data != null) { logic.getGetewayListData(); } }, child: Text( '下一步', style: TextStyle(fontSize: 24.sp, color: Colors.white), )), ), ); } }