import 'package:flutter/cupertino.dart'; 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/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/lockUserList/lockUserList_entity.dart'; import 'package:star_lock/mine/mineSet/lockUserManage/lockUserManageList/lockUserManageList_state.dart'; import 'package:star_lock/tools/noData.dart'; import '../../../../../appRouters.dart'; import '../../../../../app_settings/app_colors.dart'; import '../../../../../tools/titleAppBar.dart'; import '../../../../tools/EasyRefreshTool.dart'; import '../../../../tools/customNetworkImage.dart'; import '../../../../tools/keySearchWidget.dart'; import '../../../../tools/showIosTipView.dart'; import 'lockUserManageList_logic.dart'; class LockUserManageListPage extends StatefulWidget { const LockUserManageListPage({Key? key}) : super(key: key); @override State createState() => _LockUserManageListPageState(); } class _LockUserManageListPageState extends State { final LockUserManageListLogic logic = Get.put(LockUserManageListLogic()); final LockUserManageListState state = Get.find().state; Future getHttpData() async { logic.lockUserListRequest().then((LockUserListEntity value) { if (mounted) { setState(() {}); } }); } @override void initState() { super.initState(); getHttpData(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: '锁用户管理'.tr, haveBack: true, backgroundColor: AppColors.mainColor, actionsList: [ TextButton( child: Text( '即将到期'.tr, style: TextStyle(color: Colors.white, fontSize: 24.sp), ), onPressed: () { Navigator.pushNamed(context, Routers.expireLockManagePage); }, ), ], ), body: EasyRefreshTool( onRefresh: () { logic.pageNo = 1; getHttpData(); }, onLoad: () { getHttpData(); }, child: Column( children: [ KeySearchWidget( editingController: state.searchController, onSubmittedAction: () { logic.pageNo = 1; getHttpData(); }, ), SizedBox( height: 20.h, ), Obx(() => Expanded(child: _buildMainUI())), SizedBox( width: ScreenUtil().screenWidth - 40.w, height: 90.h, child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.white, ), onPressed: () { Navigator.pushNamed( context, Routers.massSendElectronicKeyManagePage) .then((Object? value) { logic.lockUserListRequest(); }); }, child: Text( '群发钥匙'.tr, style: TextStyle( color: AppColors.mainColor, fontSize: 24.sp, fontWeight: FontWeight.w600), )), ), SizedBox( height: 64.h, ) ], ), ), ); } Widget _buildMainUI() { return state.dataList.isEmpty ? NoData( noDataHeight: 1.sh - ScreenUtil().statusBarHeight - ScreenUtil().bottomBarHeight - 190.h - 64.h) : SlidableAutoCloseBehavior( child: ListView.separated( itemCount: state.dataList.length, itemBuilder: (BuildContext c, int index) { final LockUserItemData indexEntity = state.dataList[index]; if (index < state.dataList.length) { return Slidable( key: ValueKey(indexEntity.uid), endActionPane: ActionPane( extentRatio: 0.2, motion: const ScrollMotion(), children: [ SlidableAction( onPressed: (BuildContext context) { showIosTipViewDialog(context, indexEntity); }, backgroundColor: Colors.red, foregroundColor: Colors.white, label: '删除'.tr, padding: EdgeInsets.only(left: 5.w, right: 5.w), ), ], ), child: _electronicKeyItem(indexEntity), ); } return const SizedBox.shrink(); // return _electronicKeyItem(indexEntity); }, separatorBuilder: (BuildContext context, int index) { return const Divider( height: 1, color: AppColors.greyLineColor, ); }, ), ); } Widget _electronicKeyItem(LockUserItemData itemData) { return GestureDetector( onTap: () { Navigator.pushNamed(context, Routers.ownedKeyListPage, arguments: {'uid': itemData.uid}); }, child: Container( // height: 90.h, color: Colors.white, padding: EdgeInsets.only(top: 15.h, bottom: 15.h), // decoration: BoxDecoration( // color: Colors.white, // borderRadius: BorderRadius.circular(10.w), // ), child: Row( children: [ SizedBox(width: 30.w), SizedBox( width: 60.w, height: 60.w, child: ClipRRect( borderRadius: BorderRadius.circular(30.w), child: CustomNetworkImage( url: itemData.headUrl ?? '', defaultUrl: 'images/controls_user.png', width: 105.w, height: 105.h, ), ), ), SizedBox( width: 20.w, ), SizedBox( width: 1.sw - 30.w - 60.w - 20.w - 20.w - 20.w - 12.w, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Expanded( child: Text( itemData.nickname ?? '', style: TextStyle( fontSize: 24.sp, color: AppColors.blackColor), ), ), ], ), SizedBox(height: 5.h), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Text( itemData.userid ?? '', style: TextStyle( fontSize: 18.sp, color: AppColors.placeholderTextColor), ), ], ), SizedBox(width: 20.h), ], ), ), Image.asset( 'images/icon_right_grey.png', width: 12.w, height: 21.w, ), SizedBox(width: 20.w), ], ), ), ); } void showIosTipViewDialog( BuildContext context, LockUserItemData lockUserData) { showDialog( context: context, builder: (BuildContext context) { return ShowIosTipView( title: '提示'.tr, tipTitle: '删除用户时,会将用户拥有的钥匙一起删除。'.tr, sureClick: () { Get.back(); logic.deletelockUserRequest(lockUserData.uid!); }, cancelClick: () { Get.back(); }, ); }); } }