mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-14 09:17:37 +00:00
dynamic update
This commit is contained in:
@ -29,8 +29,8 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
// Store created spaces
|
// Store created spaces
|
||||||
List<SpaceData> spaces = [];
|
List<SpaceData> spaces = [];
|
||||||
List<Connection> connections = [];
|
List<Connection> connections = [];
|
||||||
double canvasWidth = 4000; // Initial canvas width
|
double canvasWidth = 1000; // Initial canvas width
|
||||||
double canvasHeight = 4000; // Initial canvas height
|
double canvasHeight = 1000; // Initial canvas height
|
||||||
|
|
||||||
// Track whether to show the community list view or community structure
|
// Track whether to show the community list view or community structure
|
||||||
|
|
||||||
@ -49,20 +49,31 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateCanvasSize() {
|
void updateCanvasSize() {
|
||||||
|
print("test");
|
||||||
double maxX = 0;
|
double maxX = 0;
|
||||||
double maxY = 0;
|
double maxY = 0;
|
||||||
|
|
||||||
|
// Calculate the maximum X and Y positions of all spaces
|
||||||
for (var space in spaces) {
|
for (var space in spaces) {
|
||||||
maxX = max(maxX, space.position.dx + 150); // Width of space
|
print(
|
||||||
maxY = max(maxY, space.position.dy + 60); // Height of space
|
"Space Position: ${space.position.dx}, ${space.position.dy}"); // Log the position of each space
|
||||||
|
maxX = max(maxX, space.position.dx + 150); // Add width of space
|
||||||
|
maxY = max(maxY, space.position.dy + 60); // Add height of space
|
||||||
}
|
}
|
||||||
print("Max X: $maxX, Max Y: $maxY");
|
|
||||||
|
|
||||||
|
// Add padding (but avoid adding arbitrary amounts like 1000)
|
||||||
|
double newWidth =
|
||||||
|
max(maxX + 500, canvasWidth); // Use max to ensure the canvas only grows
|
||||||
|
double newHeight = max(maxY + 500, canvasHeight);
|
||||||
|
|
||||||
|
// Set the new canvas size dynamically
|
||||||
setState(() {
|
setState(() {
|
||||||
canvasWidth = max(canvasWidth, maxX + 200); // Ensure padding
|
canvasWidth = newWidth;
|
||||||
canvasHeight = max(canvasHeight, maxY + 200); // Ensure padding
|
canvasHeight = newHeight;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Log the updated canvas size for debugging
|
||||||
|
print("Max X: $maxX, Max Y: $maxY");
|
||||||
print("Updated canvas size: $canvasWidth x $canvasHeight");
|
print("Updated canvas size: $canvasWidth x $canvasHeight");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,9 +219,11 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
position: space.position,
|
position: space.position,
|
||||||
isHovered: space.isHovered,
|
isHovered: space.isHovered,
|
||||||
onPanUpdate: (int index, Offset delta) {
|
onPanUpdate: (int index, Offset delta) {
|
||||||
|
debugPrint("Check it works");
|
||||||
setState(() {
|
setState(() {
|
||||||
spaces[index].position += delta;
|
spaces[index].position += delta;
|
||||||
});
|
});
|
||||||
|
updateCanvasSize();
|
||||||
},
|
},
|
||||||
onHoverChanged:
|
onHoverChanged:
|
||||||
(int index, bool isHovered) {
|
(int index, bool isHovered) {
|
||||||
@ -255,8 +268,6 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return CreateSpaceDialog(
|
return CreateSpaceDialog(
|
||||||
onCreateSpace: (String name, String icon) {
|
onCreateSpace: (String name, String icon) {
|
||||||
updateCanvasSize();
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
// Set the first space in the center or use passed position
|
// Set the first space in the center or use passed position
|
||||||
Offset centerPosition = position ??
|
Offset centerPosition = position ??
|
||||||
@ -269,6 +280,7 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
SpaceData newSpace =
|
SpaceData newSpace =
|
||||||
SpaceData(name: name, icon: icon, position: centerPosition);
|
SpaceData(name: name, icon: icon, position: centerPosition);
|
||||||
spaces.add(newSpace);
|
spaces.add(newSpace);
|
||||||
|
updateCanvasSize();
|
||||||
|
|
||||||
// Add connection for down-button
|
// Add connection for down-button
|
||||||
if (parentIndex != null && direction != null) {
|
if (parentIndex != null && direction != null) {
|
||||||
|
@ -26,6 +26,7 @@ class SpaceCardWidget extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
onPanUpdate: (details) {
|
onPanUpdate: (details) {
|
||||||
// Call the provided callback to update the position
|
// Call the provided callback to update the position
|
||||||
onPanUpdate(index, details.delta);
|
onPanUpdate(index, details.delta);
|
||||||
|
Reference in New Issue
Block a user