mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
models
This commit is contained in:
27
lib/features/app_layout/model/community_model.dart
Normal file
27
lib/features/app_layout/model/community_model.dart
Normal file
@ -0,0 +1,27 @@
|
||||
class Community {
|
||||
final String uuid;
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
Community({
|
||||
required this.uuid,
|
||||
required this.name,
|
||||
required this.description,
|
||||
});
|
||||
|
||||
factory Community.fromJson(Map<String, dynamic> json) {
|
||||
return Community(
|
||||
uuid: json['uuid'],
|
||||
name: json['name'],
|
||||
description: json['description'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'name': name,
|
||||
'description': description,
|
||||
};
|
||||
}
|
||||
}
|
@ -1,36 +1,45 @@
|
||||
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class SpaceModel {
|
||||
final String? id;
|
||||
final String? name;
|
||||
final SpaceType type;
|
||||
late List<RoomModel>? rooms;
|
||||
final String id;
|
||||
final String name;
|
||||
final Community community;
|
||||
final List<SubSpaceModel> subspaces;
|
||||
|
||||
SpaceModel({
|
||||
required this.type,
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.rooms,
|
||||
required this.community,
|
||||
this.subspaces = const [], // Default to an empty list
|
||||
});
|
||||
|
||||
/// Converts the instance into JSON format.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'rooms': rooms,
|
||||
'spaceName': name,
|
||||
'community': community.toJson(),
|
||||
'subspaces': subspaces.map((room) => room.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Factory constructor to create an instance from JSON.
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
final spaceData = json['space'] as Map<String, dynamic>? ?? {};
|
||||
|
||||
return SpaceModel(
|
||||
id: json['uuid'],
|
||||
name: json['name'],
|
||||
type: spaceTypesMap[json['type']]!,
|
||||
rooms: [],
|
||||
id: json['uuid'] ?? '',
|
||||
name: spaceData['spaceName'] ?? 'Unnamed Space',
|
||||
community: Community.fromJson(spaceData['community'] ?? {}),
|
||||
subspaces: (spaceData['subspaces'] as List<dynamic>?)
|
||||
?.map((item) => SubSpaceModel.fromJson(item))
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
/// Helper method to parse a list of SpaceModel from JSON.
|
||||
static List<SpaceModel> fromJsonList(List<dynamic> jsonList) {
|
||||
return jsonList.map((item) => SpaceModel.fromJson(item)).toList();
|
||||
}
|
||||
|
Reference in New Issue
Block a user