mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Refactor RoutineDevices to consolidate device data preparation in a single map to remove code duplication.
This commit is contained in:
@ -42,37 +42,32 @@ class _RoutineDevicesState extends State<RoutineDevices> {
|
|||||||
runSpacing: 10,
|
runSpacing: 10,
|
||||||
children: deviceList.asMap().entries.map((entry) {
|
children: deviceList.asMap().entries.map((entry) {
|
||||||
final device = entry.value;
|
final device = entry.value;
|
||||||
|
|
||||||
|
final deviceData = {
|
||||||
|
'device': device,
|
||||||
|
'imagePath': device.getDefaultIcon(device.productType),
|
||||||
|
'title': device.name ?? '',
|
||||||
|
'deviceId': device.uuid,
|
||||||
|
'productType': device.productType,
|
||||||
|
'functions': device.functions,
|
||||||
|
'uniqueCustomId': '',
|
||||||
|
};
|
||||||
|
|
||||||
if (state.searchText != null && state.searchText!.isNotEmpty) {
|
if (state.searchText != null && state.searchText!.isNotEmpty) {
|
||||||
return device.name!
|
return device.name!
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(state.searchText!.toLowerCase())
|
.contains(state.searchText!.toLowerCase())
|
||||||
? DraggableCard(
|
? DraggableCard(
|
||||||
imagePath: device.getDefaultIcon(device.productType),
|
imagePath: deviceData['imagePath'] as String,
|
||||||
title: device.name ?? '',
|
title: deviceData['title'] as String,
|
||||||
deviceData: {
|
deviceData: deviceData,
|
||||||
'device': device,
|
|
||||||
'imagePath': device.getDefaultIcon(device.productType),
|
|
||||||
'title': device.name ?? '',
|
|
||||||
'deviceId': device.uuid,
|
|
||||||
'productType': device.productType,
|
|
||||||
'functions': device.functions,
|
|
||||||
'uniqueCustomId': '',
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
: const SizedBox.shrink();
|
: const SizedBox.shrink();
|
||||||
} else {
|
} else {
|
||||||
return DraggableCard(
|
return DraggableCard(
|
||||||
imagePath: device.getDefaultIcon(device.productType),
|
imagePath: deviceData['imagePath'] as String,
|
||||||
title: device.name ?? '',
|
title: deviceData['title'] as String,
|
||||||
deviceData: {
|
deviceData: deviceData,
|
||||||
'device': device,
|
|
||||||
'imagePath': device.getDefaultIcon(device.productType),
|
|
||||||
'title': device.name ?? '',
|
|
||||||
'deviceId': device.uuid,
|
|
||||||
'productType': device.productType,
|
|
||||||
'functions': device.functions,
|
|
||||||
'uniqueCustomId': '',
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}).toList(),
|
}).toList(),
|
||||||
|
Reference in New Issue
Block a user