mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
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.
This commit is contained in:
@ -1,15 +1,19 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
class Product extends Equatable {
|
class Product extends Equatable {
|
||||||
final String uuid;
|
|
||||||
final String name;
|
|
||||||
final String productType;
|
|
||||||
const Product({
|
const Product({
|
||||||
required this.uuid,
|
required this.uuid,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.productType,
|
required this.productType,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final String uuid;
|
||||||
|
final String name;
|
||||||
|
final String productType;
|
||||||
|
|
||||||
|
String get icon => _mapIconToProduct(productType);
|
||||||
|
|
||||||
factory Product.fromJson(Map<String, dynamic> json) {
|
factory Product.fromJson(Map<String, dynamic> json) {
|
||||||
return Product(
|
return Product(
|
||||||
uuid: json['uuid'] as String? ?? '',
|
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
|
@override
|
||||||
List<Object?> get props => [uuid, name, productType];
|
List<Object?> get props => [uuid, name, productType];
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,10 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
|||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
class ProductTypeCard extends StatelessWidget {
|
class ProductTypeCard extends StatelessWidget {
|
||||||
const ProductTypeCard({super.key, required this.product});
|
const ProductTypeCard({
|
||||||
|
required this.product,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
final Product product;
|
final Product product;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -18,7 +21,7 @@ class ProductTypeCard extends StatelessWidget {
|
|||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(4.0),
|
padding: const EdgeInsets.all(4),
|
||||||
child: Column(
|
child: Column(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
@ -26,7 +29,7 @@ class ProductTypeCard extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: DeviceIconWidget(
|
child: DeviceIconWidget(
|
||||||
icon: product.name,
|
icon: product.icon,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_buildName(context, product.name),
|
_buildName(context, product.name),
|
||||||
|
Reference in New Issue
Block a user