feat: xhj 设备列表 添加搜索功能

This commit is contained in:
anfe 2024-06-03 17:26:32 +08:00
parent f9fdb1b6ce
commit 4f75d1a43a
4 changed files with 112 additions and 27 deletions

View File

@ -97,6 +97,14 @@ class GroupList {
} }
return data; return data;
} }
GroupList copy(){
return GroupList(
groupName: groupName,
groupId: groupId,
lockList: lockList?.map((e) => e.copy()).toList(),
);
}
} }
class LockListInfoItemEntity { class LockListInfoItemEntity {
@ -268,6 +276,10 @@ class LockListInfoItemEntity {
bool isLockOwnerBool() { bool isLockOwnerBool() {
return isLockOwner == 1; return isLockOwner == 1;
} }
LockListInfoItemEntity copy(){
return LockListInfoItemEntity.fromJson(toJson());
}
} }
class Bluetooth { class Bluetooth {

View File

@ -23,20 +23,30 @@ import '../entity/lockListInfo_entity.dart';
import 'lockList_state.dart'; import 'lockList_state.dart';
class LockListLogic extends BaseGetXController { class LockListLogic extends BaseGetXController {
LockListLogic(this.entity){ LockListLogic(this.entity) {}
}
LockListState state = LockListState(); LockListState state = LockListState();
List<GroupList> groupDataList = <GroupList>[]; List<GroupList> _groupDataList = <GroupList>[];
LockListInfoGroupEntity? entity; LockListInfoGroupEntity? entity;
List<GroupList> get groupDataList {
final List<GroupList> list = _groupDataList.map((e)=>e.copy()).toList();
if (state.searchStr.value != '' && state.showSearch.value) {
list.forEach((GroupList element) {
element.lockList?.removeWhere((LockListInfoItemEntity element) =>
!(element.lockAlias?.contains(state.searchStr.value) ?? true));
});
}
return list;
}
// //
void setLockListInfoGroupEntity(LockListInfoGroupEntity entity) { void setLockListInfoGroupEntity(LockListInfoGroupEntity entity) {
this.entity = entity; this.entity = entity;
if (entity.pageNo == 1) { if (entity.pageNo == 1) {
groupDataList = <GroupList>[]; _groupDataList = <GroupList>[];
} }
groupDataList.addAll(entity.groupList!); _groupDataList.addAll(entity.groupList!);
update(); update();
} }

View File

@ -6,10 +6,12 @@ import '../entity/lockListInfo_entity.dart';
class LockListState{ class LockListState{
var itemStatusIsEable = false.obs; // item是否能点击 RxBool itemStatusIsEable = false.obs; // item是否能点击
LockListInfoItemEntity lockListInfoItemEntity = LockListInfoItemEntity(); // item LockListInfoItemEntity lockListInfoItemEntity = LockListInfoItemEntity(); // item
var passwordTF = TextEditingController(); TextEditingController passwordTF = TextEditingController();
var deleteAdministratorIsHaveAllData = false.obs; // RxBool deleteAdministratorIsHaveAllData = false.obs; //
var ifCurrentScreen = true.obs; // , RxBool ifCurrentScreen = true.obs; // ,
RxBool showSearch = false.obs; // ,
RxString searchStr = ''.obs; // ,
} }

View File

@ -43,16 +43,75 @@ class _LockListXHJPageState extends State<LockListXHJPage> with RouteAware {
children: <Widget>[ children: <Widget>[
Align( Align(
alignment: Alignment.topRight, alignment: Alignment.topRight,
child: IconButton( child: Row(
onPressed: () { mainAxisSize: MainAxisSize.min,
Get.toNamed(Routers.selectLockTypePage); children: <Widget>[
}, IconButton(
icon: Icon( onPressed: () {
Icons.add_circle, state.showSearch.value = !state.showSearch.value;
size: 48.w, },
color: AppColors.mainColor, icon: Icon(
)), Icons.search,
size: 32.w,
color: AppColors.blackColor,
)),
IconButton(
onPressed: () {
Get.toNamed(Routers.selectLockTypePage);
},
icon: Icon(
Icons.add_circle,
size: 48.w,
color: AppColors.mainColor,
)),
],
),
), ),
//
Obx(() {
return state.showSearch.value
? Container(
height: 50.w,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.8),
borderRadius: BorderRadius.circular(40.w),
),
margin: EdgeInsets.only(
left: 25.w, right: 25.w, bottom: 20.h),
child: Stack(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 14.h, left: 20.w),
child: Icon(
Icons.search,
size: 28.w,
color: AppColors.blackColor,
),
),
TextField(
decoration: InputDecoration(
hintText: '搜索'.tr,
hintStyle: TextStyle(
fontSize: 24.sp,
color: AppColors.blackColor,
),
border: InputBorder.none,
contentPadding: EdgeInsets.only(
top: 6.h,
left: 50.w,
),
isCollapsed: true,
),
onChanged: (String value) {
state.searchStr.value = value;
},
autofocus: true,
),
],
),
)
: const SizedBox.shrink();
}),
Padding( Padding(
padding: EdgeInsets.only(left: 45.w), padding: EdgeInsets.only(left: 45.w),
child: Text( child: Text(
@ -65,15 +124,17 @@ class _LockListXHJPageState extends State<LockListXHJPage> with RouteAware {
), ),
), ),
Expanded( Expanded(
child: ListView.builder( child: Obx(() {
itemCount: logic.groupDataList.length, return ListView.builder(
itemBuilder: (BuildContext context, int index) { itemCount: logic.groupDataList.length,
final GroupList itemData = logic.groupDataList[index]; itemBuilder: (BuildContext context, int index) {
return _buildLockExpandedList(context, index, itemData); final GroupList itemData = logic.groupDataList[index];
}, return _buildLockExpandedList(context, index, itemData);
shrinkWrap: true, },
physics: const AlwaysScrollableScrollPhysics(), shrinkWrap: true,
), physics: const AlwaysScrollableScrollPhysics(),
);
}),
), ),
], ],
), ),