subspace model added

This commit is contained in:
hannathkadher
2024-10-29 18:44:41 +04:00
parent 1558996891
commit 5a7ed3ec7c
2 changed files with 44 additions and 4 deletions

View File

@ -1,13 +1,16 @@
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class SubSpaceModel {
class RoomModel {
final String? id;
final String? name;
final SpaceType type;
List<DeviceModel>? devices;
SubSpaceModel({
RoomModel({
required this.id,
required this.name,
required this.type,
required this.devices,
});
@ -15,20 +18,22 @@ class SubSpaceModel {
return {
'id': id,
'name': name,
'type': type,
'devices': devices,
};
}
factory SubSpaceModel.fromJson(Map<String, dynamic> json) {
factory RoomModel.fromJson(Map<String, dynamic> json) {
List<DeviceModel> devices = [];
if (json['devices'] != null) {
for (var device in json['devices']) {
devices.add(DeviceModel.fromJson(device));
}
}
return SubSpaceModel(
return RoomModel(
id: json['uuid'],
name: json['name'],
type: spaceTypesMap[json['type']]!,
devices: [],
);
}

View File

@ -0,0 +1,35 @@
import 'package:syncrow_app/features/devices/model/device_model.dart';
class SubSpaceModel {
final String? id;
final String? name;
List<DeviceModel>? devices;
SubSpaceModel({
required this.id,
required this.name,
required this.devices,
});
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'devices': devices,
};
}
factory SubSpaceModel.fromJson(Map<String, dynamic> json) {
List<DeviceModel> devices = [];
if (json['devices'] != null) {
for (var device in json['devices']) {
devices.add(DeviceModel.fromJson(device));
}
}
return SubSpaceModel(
id: json['uuid'],
name: json['name'],
devices: [],
);
}
}