mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Enhance Product Model and SpaceDetailsDevicesBox:
- Added 'productType' field to Product model for improved data representation. - Updated JSON parsing in Product model to handle 'prodType'. - Refactored SpaceDetailsDevicesBox to utilize productType for dynamic device icon rendering, enhancing UI clarity and maintainability.
This commit is contained in:
@ -3,16 +3,18 @@ import 'package:equatable/equatable.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,
|
||||
});
|
||||
|
||||
factory Product.fromJson(Map<String, dynamic> json) {
|
||||
return Product(
|
||||
uuid: json['uuid'] as String,
|
||||
name: json['name'] as String,
|
||||
uuid: json['uuid'] as String? ?? '',
|
||||
name: json['name'] as String? ?? '',
|
||||
productType: json['prodType'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
@ -20,9 +22,10 @@ class Product extends Equatable {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'name': name,
|
||||
'productType': productType,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [uuid, name];
|
||||
List<Object?> get props => [uuid, name, productType];
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_web/common/edit_chip.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/widgets/button_content_widget.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/enum/device_types.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
class SpaceDetailsDevicesBox extends StatelessWidget {
|
||||
const SpaceDetailsDevicesBox({
|
||||
@ -35,37 +38,30 @@ class SpaceDetailsDevicesBox extends StatelessWidget {
|
||||
spacing: 8.0,
|
||||
runSpacing: 8.0,
|
||||
children: [
|
||||
// Combine tags from spaceModel and subspaces
|
||||
// ...TagHelper.groupTags([
|
||||
// ...?tags,
|
||||
// ...?subspaces?.expand((subspace) => subspace.tags ?? [])
|
||||
// ]).entries.map(
|
||||
// (entry) => Chip(
|
||||
// avatar: SizedBox(
|
||||
// width: 24,
|
||||
// height: 24,
|
||||
// child: SvgPicture.asset(
|
||||
// entry.key.icon ?? 'assets/icons/gateway.svg',
|
||||
// fit: BoxFit.contain,
|
||||
// ),
|
||||
// ),
|
||||
// label: Text(
|
||||
// 'x${entry.value}',
|
||||
// style: Theme.of(context)
|
||||
// .textTheme
|
||||
// .bodySmall
|
||||
// ?.copyWith(color: ColorsManager.spaceColor),
|
||||
// ),
|
||||
// backgroundColor: ColorsManager.whiteColors,
|
||||
// shape: RoundedRectangleBorder(
|
||||
// borderRadius: BorderRadius.circular(16),
|
||||
// side: const BorderSide(
|
||||
// color: ColorsManager.spaceColor,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
|
||||
...productAllocations.map(
|
||||
(entry) => Chip(
|
||||
avatar: SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: SvgPicture.asset(
|
||||
_getDeviceIcon(entry.product.productType),
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
label: Text(
|
||||
entry.product.productType,
|
||||
style: context.textTheme.bodySmall
|
||||
?.copyWith(color: ColorsManager.spaceColor),
|
||||
),
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: const BorderSide(
|
||||
color: ColorsManager.spaceColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
EditChip(
|
||||
onTap: () {},
|
||||
),
|
||||
@ -83,10 +79,37 @@ class SpaceDetailsDevicesBox extends StatelessWidget {
|
||||
child: ButtonContentWidget(
|
||||
svgAssets: Assets.addIcon,
|
||||
label: 'Add Devices',
|
||||
// disabled: isTagsAndSubspaceModelDisabled,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _getDeviceIcon(String productType) =>
|
||||
switch (devicesTypesMap[productType]) {
|
||||
DeviceType.LightBulb => Assets.lightBulb,
|
||||
DeviceType.CeilingSensor => Assets.sensors,
|
||||
DeviceType.AC => Assets.ac,
|
||||
DeviceType.DoorLock => Assets.doorLock,
|
||||
DeviceType.Curtain => Assets.curtain,
|
||||
DeviceType.ThreeGang => Assets.gangSwitch,
|
||||
DeviceType.Gateway => Assets.gateway,
|
||||
DeviceType.OneGang => Assets.oneGang,
|
||||
DeviceType.TwoGang => Assets.twoGang,
|
||||
DeviceType.WH => Assets.waterHeater,
|
||||
DeviceType.DoorSensor => Assets.openCloseDoor,
|
||||
DeviceType.GarageDoor => Assets.openedDoor,
|
||||
DeviceType.WaterLeak => Assets.waterLeakNormal,
|
||||
DeviceType.Curtain2 => Assets.curtainIcon,
|
||||
DeviceType.Blind => Assets.curtainIcon,
|
||||
DeviceType.WallSensor => Assets.sensors,
|
||||
DeviceType.DS => Assets.openCloseDoor,
|
||||
DeviceType.OneTouch => Assets.gangSwitch,
|
||||
DeviceType.TowTouch => Assets.gangSwitch,
|
||||
DeviceType.ThreeTouch => Assets.gangSwitch,
|
||||
DeviceType.NCPS => Assets.sensors,
|
||||
DeviceType.PC => Assets.powerClamp,
|
||||
DeviceType.Other => Assets.blackLogo,
|
||||
null => Assets.blackLogo,
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user