From f0bfe085a4e145a2ade2c9f926a91494a46c4fed Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Mon, 7 Jul 2025 09:34:11 +0300 Subject: [PATCH] Enhance Product Model with Icon Mapping: - Added icon mapping functionality to the Product model, allowing dynamic icon retrieval based on product type. - Updated ProductTypeCard to utilize the new icon property, improving UI representation and maintainability. --- .../products/domain/models/product.dart | 37 +++++++++++++++++-- .../widgets/product_type_card.dart | 9 +++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lib/pages/space_management_v2/modules/products/domain/models/product.dart b/lib/pages/space_management_v2/modules/products/domain/models/product.dart index aac332d6..1a505bc5 100644 --- a/lib/pages/space_management_v2/modules/products/domain/models/product.dart +++ b/lib/pages/space_management_v2/modules/products/domain/models/product.dart @@ -1,15 +1,19 @@ import 'package:equatable/equatable.dart'; +import 'package:syncrow_web/utils/constants/assets.dart'; class Product extends Equatable { - final String uuid; - final String name; - final String productType; const Product({ required this.uuid, required this.name, required this.productType, }); + final String uuid; + final String name; + final String productType; + + String get icon => _mapIconToProduct(productType); + factory Product.fromJson(Map json) { return Product( uuid: json['uuid'] as String? ?? '', @@ -26,6 +30,33 @@ class Product extends Equatable { }; } + static String _mapIconToProduct(String prodType) { + const iconMapping = { + '1G': Assets.Gang1SwitchIcon, + '1GT': Assets.oneTouchSwitch, + '2G': Assets.Gang2SwitchIcon, + '2GT': Assets.twoTouchSwitch, + '3G': Assets.Gang3SwitchIcon, + '3GT': Assets.threeTouchSwitch, + 'CUR': Assets.curtain, + 'CUR_2': Assets.curtain, + 'GD': Assets.garageDoor, + 'GW': Assets.SmartGatewayIcon, + 'DL': Assets.DoorLockIcon, + 'WL': Assets.waterLeakSensor, + 'WH': Assets.waterHeater, + 'WM': Assets.waterLeakSensor, + 'SOS': Assets.sos, + 'AC': Assets.ac, + 'CPS': Assets.presenceSensor, + 'PC': Assets.powerClamp, + 'WPS': Assets.presenceSensor, + 'DS': Assets.doorSensor + }; + + return iconMapping[prodType] ?? Assets.presenceSensor; + } + @override List get props => [uuid, name, productType]; } diff --git a/lib/pages/space_management_v2/modules/tags/presentation/widgets/product_type_card.dart b/lib/pages/space_management_v2/modules/tags/presentation/widgets/product_type_card.dart index 203e8502..d364a98a 100644 --- a/lib/pages/space_management_v2/modules/tags/presentation/widgets/product_type_card.dart +++ b/lib/pages/space_management_v2/modules/tags/presentation/widgets/product_type_card.dart @@ -6,7 +6,10 @@ import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; class ProductTypeCard extends StatelessWidget { - const ProductTypeCard({super.key, required this.product}); + const ProductTypeCard({ + required this.product, + super.key, + }); final Product product; @override @@ -18,7 +21,7 @@ class ProductTypeCard extends StatelessWidget { borderRadius: BorderRadius.circular(8), ), child: Padding( - padding: const EdgeInsets.all(4.0), + padding: const EdgeInsets.all(4), child: Column( spacing: 8, mainAxisAlignment: MainAxisAlignment.start, @@ -26,7 +29,7 @@ class ProductTypeCard extends StatelessWidget { children: [ Expanded( child: DeviceIconWidget( - icon: product.name, + icon: product.icon, ), ), _buildName(context, product.name),