added position elements to space

This commit is contained in:
hannathkadher
2024-10-08 11:39:10 +04:00
parent cdd22f8d76
commit 081d6fd65f
8 changed files with 342 additions and 198 deletions

View File

@ -1,4 +1,5 @@
import 'package:syncrow_web/pages/auth/model/region_model.dart';
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
class CommunityModel {
final String uuid;
@ -7,6 +8,7 @@ class CommunityModel {
final String name;
final String description;
final RegionModel? region;
List<SpaceModel> spaces;
CommunityModel({
required this.uuid,
@ -14,6 +16,7 @@ class CommunityModel {
required this.updatedAt,
required this.name,
required this.description,
required this.spaces,
this.region,
});
@ -26,6 +29,11 @@ class CommunityModel {
description: json['description'],
region:
json['region'] != null ? RegionModel.fromJson(json['region']) : null,
spaces: json['spaces'] != null
? (json['spaces'] as List)
.map((space) => SpaceModel.fromJson(space))
.toList()
: [],
);
}
@ -37,6 +45,9 @@ class CommunityModel {
'name': name,
'description': description,
'region': region?.toJson(),
'spaces': spaces
.map((space) => space.toMap())
.toList(), // Convert spaces to Map
};
}
}

View File

@ -1,3 +1,4 @@
import 'dart:ui';
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
class SpaceModel {
@ -11,7 +12,10 @@ class SpaceModel {
final bool isParent;
final SpaceModel? parent;
final CommunityModel? community;
final List<SpaceModel> children; // List of child spaces
final List<SpaceModel> children;
final String icon;
Offset position;
bool isHovered;
SpaceModel({
required this.uuid,
@ -25,6 +29,9 @@ class SpaceModel {
this.parent,
this.community,
required this.children,
required this.icon,
required this.position,
this.isHovered = false,
});
factory SpaceModel.fromJson(Map<String, dynamic> json) {
@ -47,6 +54,11 @@ class SpaceModel {
.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
);
}
@ -63,6 +75,9 @@ class SpaceModel {
'parent': parent?.toMap(),
'community': community?.toMap(),
'children': children.map((child) => child.toMap()).toList(),
'icon': icon,
'position': {'dx': position.dx, 'dy': position.dy},
'isHovered': isHovered,
};
}
}