From 5a7ed3ec7c61bb15cf7ee8452857e37c92deb0cd Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Tue, 29 Oct 2024 18:44:41 +0400 Subject: [PATCH] subspace model added --- lib/features/devices/model/room_model.dart | 13 ++++--- .../devices/model/subspace_model.dart | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 lib/features/devices/model/subspace_model.dart diff --git a/lib/features/devices/model/room_model.dart b/lib/features/devices/model/room_model.dart index b2aa133..7a00b43 100644 --- a/lib/features/devices/model/room_model.dart +++ b/lib/features/devices/model/room_model.dart @@ -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? 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 json) { + factory RoomModel.fromJson(Map json) { List 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: [], ); } diff --git a/lib/features/devices/model/subspace_model.dart b/lib/features/devices/model/subspace_model.dart new file mode 100644 index 0000000..b2aa133 --- /dev/null +++ b/lib/features/devices/model/subspace_model.dart @@ -0,0 +1,35 @@ +import 'package:syncrow_app/features/devices/model/device_model.dart'; + +class SubSpaceModel { + final String? id; + final String? name; + List? devices; + + SubSpaceModel({ + required this.id, + required this.name, + required this.devices, + }); + + Map toJson() { + return { + 'id': id, + 'name': name, + 'devices': devices, + }; + } + + factory SubSpaceModel.fromJson(Map json) { + List 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: [], + ); + } +}