Files
syncrow-app/lib/features/devices/model/device_model.dart
Mohammad Salameh fbe2f5fe53 !! BIG CHANGE TO ASSETS GEN !!
changed the method of generating assets to be more declrative when it comes to names of the assets.

it now include the file path name e.g (asset in the path "assets/images/home-images/home.png" will be generated as this "String assetsImagesHomeImageshome = "path" ".

this will be very helpful in the future when we want to orgnize the assets dir.
2024-05-07 12:26:12 +03:00

98 lines
2.6 KiB
Dart

import 'package:syncrow_app/features/devices/model/function_model.dart';
import 'package:syncrow_app/features/devices/model/status_model.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class DeviceModel {
int? activeTime;
// String? id;
String? localKey;
String? model;
String? name;
String? icon;
bool? isOnline;
List<StatusModel> status = [];
String? productName;
String? timeZone;
int? updateTime;
String? uuid;
DeviceType? productType;
bool isSelected = false;
late List<FunctionModel> functions;
DeviceModel({
this.activeTime,
// this.id,
this.localKey,
this.model,
this.name,
this.isOnline,
required this.status,
this.productName,
this.timeZone,
this.updateTime,
this.uuid,
this.productType,
this.icon,
}) {
functions = getFunctions(productType!);
}
factory DeviceModel.fromJson(Map<String, dynamic> json) {
String tempIcon = '';
DeviceType type = devicesTypesMap[json['productType']] ?? DeviceType.Other;
if (type == DeviceType.LightBulb) {
tempIcon = Assets.assetsIconsLight;
} else if (type == DeviceType.CeilingSensor ||
type == DeviceType.WallSensor) {
tempIcon = Assets.assetsIconsSensors;
} else if (type == DeviceType.AC) {
tempIcon = Assets.assetsIconsAC;
} else if (type == DeviceType.DoorLock) {
tempIcon = Assets.assetsIconsDoorLock;
} else if (type == DeviceType.Curtain) {
tempIcon = Assets.assetsIconsCurtain;
} else if (type == DeviceType.ThreeGang) {
tempIcon = Assets.assetsIcons3GangSwitch;
} else if (type == DeviceType.Gateway) {
tempIcon = Assets.assetsIconsGateway;
} else {
tempIcon = Assets.assetsIconsLogo;
}
return DeviceModel(
icon: tempIcon,
activeTime: json['activeTime'],
// id: json['id'],
localKey: json['localKey'],
model: json['model'],
name: json['name'],
isOnline: json['online'],
productName: json['productName'],
timeZone: json['timeZone'],
updateTime: json['updateTime'],
uuid: json['uuid'],
productType: type,
status: [],
);
}
Map<String, dynamic> toJson() {
return {
'activeTime': activeTime,
// 'id': id,
'localKey': localKey,
'model': model,
'name': name,
'online': isOnline,
'productName': productName,
'timeZone': timeZone,
'updateTime': updateTime,
'uuid': uuid,
'productType': productType,
};
}
List<FunctionModel> getFunctions(DeviceType type) =>
devicesFunctionsMap[productType] ?? [];
}