diff --git a/lib/pages/routines/widgets/routine_devices.dart b/lib/pages/routines/widgets/routine_devices.dart index ba5756e0..84fd44c0 100644 --- a/lib/pages/routines/widgets/routine_devices.dart +++ b/lib/pages/routines/widgets/routine_devices.dart @@ -17,6 +17,8 @@ class _RoutineDevicesState extends State { context.read().add(FetchDevicesInRoutine()); } + static const _allowedProductTypes = {'AC', '1G', '2G', '3G', 'WPS', 'GW'}; + @override Widget build(BuildContext context) { return BlocBuilder( @@ -31,47 +33,41 @@ class _RoutineDevicesState extends State { } }); - final deviceList = state.devices.where((device) { - const allowedProductTypes = {'AC', '1G', '2G', '3G', 'WPS', 'GW'}; - return allowedProductTypes.contains(device.productType); - }).toList(); + final deviceList = state.devices + .where((device) => _allowedProductTypes.contains(device.productType)) + .toList(); return Wrap( spacing: 10, runSpacing: 10, children: deviceList.asMap().entries.map((entry) { 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) { return device.name! .toLowerCase() .contains(state.searchText!.toLowerCase()) ? DraggableCard( - imagePath: device.getDefaultIcon(device.productType), - title: device.name ?? '', - deviceData: { - 'device': device, - 'imagePath': device.getDefaultIcon(device.productType), - 'title': device.name ?? '', - 'deviceId': device.uuid, - 'productType': device.productType, - 'functions': device.functions, - 'uniqueCustomId': '', - }, + imagePath: deviceData['imagePath'] as String, + title: deviceData['title'] as String, + deviceData: deviceData, ) : const SizedBox.shrink(); } else { return DraggableCard( - imagePath: device.getDefaultIcon(device.productType), - title: device.name ?? '', - deviceData: { - 'device': device, - 'imagePath': device.getDefaultIcon(device.productType), - 'title': device.name ?? '', - 'deviceId': device.uuid, - 'productType': device.productType, - 'functions': device.functions, - 'uniqueCustomId': '', - }, + imagePath: deviceData['imagePath'] as String, + title: deviceData['title'] as String, + deviceData: deviceData, ); } }).toList(),