mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
added incoming and outgoing connections
This commit is contained in:
@ -53,20 +53,17 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
child: Stack(
|
||||
children: [
|
||||
for (var connection in connections)
|
||||
CustomPaint(
|
||||
painter: CurvedLinePainter([connection])),
|
||||
CustomPaint(painter: CurvedLinePainter([connection])),
|
||||
for (var entry in spaces.asMap().entries)
|
||||
Positioned(
|
||||
left: entry.value.position.dx,
|
||||
top: entry.value.position.dy,
|
||||
child: SpaceCardWidget(
|
||||
index: entry.key,
|
||||
onButtonTap: (int index, Offset newPosition,
|
||||
String direction) {
|
||||
onButtonTap: (int index, Offset newPosition, String direction) {
|
||||
_showCreateSpaceDialog(
|
||||
screenSize,
|
||||
position:
|
||||
spaces[index].position + newPosition,
|
||||
position: spaces[index].position + newPosition,
|
||||
parentIndex: index,
|
||||
direction: direction,
|
||||
);
|
||||
@ -135,13 +132,12 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
if (widget.selectedCommunity != null)
|
||||
Text(
|
||||
widget.selectedCommunity!.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 16, color: ColorsManager.blackColor),
|
||||
style: const TextStyle(fontSize: 16, color: ColorsManager.blackColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
// Show "Save" button only if there are spaces
|
||||
if (spaces.isNotEmpty && widget.selectedCommunity != null )
|
||||
if (spaces.isNotEmpty && widget.selectedCommunity != null)
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
_saveSpaces();
|
||||
@ -149,14 +145,12 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
icon: const Icon(Icons.save, size: 18),
|
||||
label: const Text("Save"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
foregroundColor: Colors.black,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
||||
side: BorderSide(color: Colors.grey.shade300),
|
||||
elevation: 0,
|
||||
),
|
||||
@ -169,29 +163,19 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
void _updateNodePosition(SpaceModel node, Offset newPosition) {
|
||||
setState(() {
|
||||
node.position = newPosition;
|
||||
|
||||
// Expand canvas to the right when node approaches the right edge
|
||||
if (node.position.dx >= canvasWidth - 200) {
|
||||
canvasWidth += 200;
|
||||
}
|
||||
|
||||
// Expand canvas downward when node approaches the bottom edge
|
||||
if (node.position.dy >= canvasHeight - 200) {
|
||||
canvasHeight += 200;
|
||||
}
|
||||
|
||||
// Expand canvas to the left when node approaches the left edge
|
||||
if (node.position.dx <= 200) {
|
||||
double shiftAmount = 200;
|
||||
canvasWidth += shiftAmount;
|
||||
|
||||
// Shift all nodes to the right by shiftAmount
|
||||
for (var n in spaces) {
|
||||
n.position = Offset(n.position.dx + shiftAmount, n.position.dy);
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent nodes from going out of bounds on top edge
|
||||
if (node.position.dy < 0) {
|
||||
node.position = Offset(node.position.dx, 0);
|
||||
}
|
||||
@ -210,25 +194,30 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
Offset centerPosition = position ??
|
||||
Offset(
|
||||
screenSize.width / 2 - 75, // Center horizontally
|
||||
screenSize.height / 2 -
|
||||
50, // Slightly above the center vertically
|
||||
screenSize.height / 2 - 50, // Slightly above the center vertically
|
||||
);
|
||||
|
||||
SpaceModel newSpace =
|
||||
SpaceModel(name: name, icon: icon, position: centerPosition, isPrivate: false, children: []);
|
||||
spaces.add(newSpace);
|
||||
SpaceModel newSpace = SpaceModel(
|
||||
name: name,
|
||||
icon: icon,
|
||||
position: centerPosition,
|
||||
isPrivate: false,
|
||||
children: [],
|
||||
);
|
||||
|
||||
_updateNodePosition(newSpace, newSpace.position);
|
||||
|
||||
// Add connection for down-button
|
||||
if (parentIndex != null && direction != null) {
|
||||
SpaceModel parentSpace = spaces[parentIndex];
|
||||
newSpace.parent = parentSpace;
|
||||
parentSpace.children.add(newSpace);
|
||||
connections.add(Connection(
|
||||
startSpace: parentSpace,
|
||||
endSpace: newSpace,
|
||||
direction: direction,
|
||||
));
|
||||
}
|
||||
|
||||
spaces.add(newSpace);
|
||||
_updateNodePosition(newSpace, newSpace.position);
|
||||
});
|
||||
},
|
||||
);
|
||||
@ -243,8 +232,12 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
}
|
||||
|
||||
void _saveSpaces() {
|
||||
// Implement your save functionality here
|
||||
List<Map<String, dynamic>> spaceData = spaces.map((space) => space.toMap()).toList();
|
||||
List<Map<String, dynamic>> connectionData =
|
||||
connections.map((connection) => connection.toMap()).toList();
|
||||
|
||||
print("Spaces saved: ${spaces.length}");
|
||||
// Save to local storage, a file, or send to a backend
|
||||
print('Spaces: ${spaceData}');
|
||||
print('Connections: ${connectionData}');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user