mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
parse incoming connection
This commit is contained in:
@ -44,7 +44,8 @@ class SpaceModel {
|
||||
this.selectedProducts = const [],
|
||||
}) : internalId = internalId ?? const Uuid().v4();
|
||||
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json, {String? parentInternalId}) {
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json,
|
||||
{String? parentInternalId}) {
|
||||
final String internalId = json['internalId'] ?? const Uuid().v4();
|
||||
|
||||
final List<SpaceModel> children = json['children'] != null
|
||||
@ -56,7 +57,7 @@ class SpaceModel {
|
||||
}).toList()
|
||||
: [];
|
||||
|
||||
return SpaceModel(
|
||||
final instance = SpaceModel(
|
||||
internalId: internalId,
|
||||
uuid: json['uuid'] ?? '',
|
||||
spaceTuyaUuid: json['spaceTuyaUuid'],
|
||||
@ -72,11 +73,14 @@ class SpaceModel {
|
||||
isPrivate: json['parent']?['isPrivate'] ?? false,
|
||||
invitationCode: json['parent']?['invitationCode'],
|
||||
children: [],
|
||||
position: Offset(json['parent']?['x'] ?? 0, json['parent']?['y'] ?? 0),
|
||||
position:
|
||||
Offset(json['parent']?['x'] ?? 0, json['parent']?['y'] ?? 0),
|
||||
icon: json['parent']?['icon'] ?? Assets.location,
|
||||
)
|
||||
: null,
|
||||
community: json['community'] != null ? CommunityModel.fromJson(json['community']) : null,
|
||||
community: json['community'] != null
|
||||
? CommunityModel.fromJson(json['community'])
|
||||
: null,
|
||||
children: children,
|
||||
icon: json['icon'] ?? Assets.location,
|
||||
position: Offset(json['x'] ?? 0, json['y'] ?? 0),
|
||||
@ -90,6 +94,20 @@ class SpaceModel {
|
||||
}).toList()
|
||||
: [],
|
||||
);
|
||||
|
||||
if (json['incomingConnections'] != null &&
|
||||
json['incomingConnections'] is List &&
|
||||
(json['incomingConnections'] as List).isNotEmpty &&
|
||||
instance.parent != null) {
|
||||
final conn = json['incomingConnections'][0];
|
||||
instance.incomingConnection = Connection(
|
||||
startSpace: instance.parent ?? instance, // Parent space
|
||||
endSpace: instance, // This space instance
|
||||
direction: conn['direction'],
|
||||
);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
|
Reference in New Issue
Block a user