mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +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 {
|
class Product extends Equatable {
|
||||||
final String uuid;
|
final String uuid;
|
||||||
final String name;
|
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,
|
||||||
});
|
});
|
||||||
|
|
||||||
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? ?? '',
|
||||||
name: json['name'] as String,
|
name: json['name'] as String? ?? '',
|
||||||
|
productType: json['prodType'] as String? ?? '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,9 +22,10 @@ class Product extends Equatable {
|
|||||||
return {
|
return {
|
||||||
'uuid': uuid,
|
'uuid': uuid,
|
||||||
'name': name,
|
'name': name,
|
||||||
|
'productType': productType,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@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/material.dart';
|
||||||
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:syncrow_web/common/edit_chip.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/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/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/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.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 {
|
class SpaceDetailsDevicesBox extends StatelessWidget {
|
||||||
const SpaceDetailsDevicesBox({
|
const SpaceDetailsDevicesBox({
|
||||||
@ -35,37 +38,30 @@ class SpaceDetailsDevicesBox extends StatelessWidget {
|
|||||||
spacing: 8.0,
|
spacing: 8.0,
|
||||||
runSpacing: 8.0,
|
runSpacing: 8.0,
|
||||||
children: [
|
children: [
|
||||||
// Combine tags from spaceModel and subspaces
|
...productAllocations.map(
|
||||||
// ...TagHelper.groupTags([
|
(entry) => Chip(
|
||||||
// ...?tags,
|
avatar: SizedBox(
|
||||||
// ...?subspaces?.expand((subspace) => subspace.tags ?? [])
|
width: 24,
|
||||||
// ]).entries.map(
|
height: 24,
|
||||||
// (entry) => Chip(
|
child: SvgPicture.asset(
|
||||||
// avatar: SizedBox(
|
_getDeviceIcon(entry.product.productType),
|
||||||
// width: 24,
|
fit: BoxFit.contain,
|
||||||
// height: 24,
|
),
|
||||||
// child: SvgPicture.asset(
|
),
|
||||||
// entry.key.icon ?? 'assets/icons/gateway.svg',
|
label: Text(
|
||||||
// fit: BoxFit.contain,
|
entry.product.productType,
|
||||||
// ),
|
style: context.textTheme.bodySmall
|
||||||
// ),
|
?.copyWith(color: ColorsManager.spaceColor),
|
||||||
// label: Text(
|
),
|
||||||
// 'x${entry.value}',
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
// style: Theme.of(context)
|
shape: RoundedRectangleBorder(
|
||||||
// .textTheme
|
borderRadius: BorderRadius.circular(16),
|
||||||
// .bodySmall
|
side: const BorderSide(
|
||||||
// ?.copyWith(color: ColorsManager.spaceColor),
|
color: ColorsManager.spaceColor,
|
||||||
// ),
|
),
|
||||||
// backgroundColor: ColorsManager.whiteColors,
|
),
|
||||||
// shape: RoundedRectangleBorder(
|
),
|
||||||
// borderRadius: BorderRadius.circular(16),
|
),
|
||||||
// side: const BorderSide(
|
|
||||||
// color: ColorsManager.spaceColor,
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
|
|
||||||
EditChip(
|
EditChip(
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
),
|
),
|
||||||
@ -83,10 +79,37 @@ class SpaceDetailsDevicesBox extends StatelessWidget {
|
|||||||
child: ButtonContentWidget(
|
child: ButtonContentWidget(
|
||||||
svgAssets: Assets.addIcon,
|
svgAssets: Assets.addIcon,
|
||||||
label: 'Add Devices',
|
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