mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
84 lines
2.5 KiB
Dart
84 lines
2.5 KiB
Dart
import 'dart:ui';
|
|
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
|
|
|
class SpaceModel {
|
|
final String uuid;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
final String? spaceTuyaUuid;
|
|
final String name;
|
|
final bool isPrivate;
|
|
final String? invitationCode;
|
|
final bool isParent;
|
|
final SpaceModel? parent;
|
|
final CommunityModel? community;
|
|
final List<SpaceModel> children;
|
|
final String icon;
|
|
Offset position;
|
|
bool isHovered;
|
|
|
|
SpaceModel({
|
|
required this.uuid,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
this.spaceTuyaUuid,
|
|
required this.name,
|
|
required this.isPrivate,
|
|
this.invitationCode,
|
|
required this.isParent,
|
|
this.parent,
|
|
this.community,
|
|
required this.children,
|
|
required this.icon,
|
|
required this.position,
|
|
this.isHovered = false,
|
|
});
|
|
|
|
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
|
return SpaceModel(
|
|
uuid: json['uuid'],
|
|
createdAt: DateTime.parse(json['createdAt']),
|
|
updatedAt: DateTime.parse(json['updatedAt']),
|
|
spaceTuyaUuid: json['spaceTuyaUuid'],
|
|
name: json['name'],
|
|
isPrivate: json['isPrivate'],
|
|
invitationCode: json['invitationCode'],
|
|
isParent: json['isParent'],
|
|
parent:
|
|
json['parent'] != null ? SpaceModel.fromJson(json['parent']) : null,
|
|
community: json['community'] != null
|
|
? CommunityModel.fromJson(json['community'])
|
|
: null,
|
|
children: json['children'] != null
|
|
? (json['children'] as List)
|
|
.map((child) => SpaceModel.fromJson(child))
|
|
.toList()
|
|
: [],
|
|
icon: json['icon'], // New field from JSON
|
|
position: json['position'] != null
|
|
? Offset(json['position']['dx'], json['position']['dy'])
|
|
: Offset(0, 0), // Default position if not provided in JSON
|
|
isHovered: json['isHovered'] ?? false, // Default isHovered if not in JSON
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'uuid': uuid,
|
|
'createdAt': createdAt.toIso8601String(),
|
|
'updatedAt': updatedAt.toIso8601String(),
|
|
'spaceTuyaUuid': spaceTuyaUuid,
|
|
'name': name,
|
|
'isPrivate': isPrivate,
|
|
'invitationCode': invitationCode,
|
|
'isParent': isParent,
|
|
'parent': parent?.toMap(),
|
|
'community': community?.toMap(),
|
|
'children': children.map((child) => child.toMap()).toList(),
|
|
'icon': icon,
|
|
'position': {'dx': position.dx, 'dy': position.dy},
|
|
'isHovered': isHovered,
|
|
};
|
|
}
|
|
}
|