dynamic update

This commit is contained in:
hannathkadher
2024-10-14 11:11:11 +04:00
parent df3b3131be
commit 3f9bd10582
2 changed files with 22 additions and 9 deletions

View File

@ -29,8 +29,8 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
// Store created spaces
List<SpaceData> spaces = [];
List<Connection> connections = [];
double canvasWidth = 4000; // Initial canvas width
double canvasHeight = 4000; // Initial canvas height
double canvasWidth = 1000; // Initial canvas width
double canvasHeight = 1000; // Initial canvas height
// Track whether to show the community list view or community structure
@ -49,20 +49,31 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
}
void updateCanvasSize() {
print("test");
double maxX = 0;
double maxY = 0;
// Calculate the maximum X and Y positions of all spaces
for (var space in spaces) {
maxX = max(maxX, space.position.dx + 150); // Width of space
maxY = max(maxY, space.position.dy + 60); // Height of space
print(
"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(() {
canvasWidth = max(canvasWidth, maxX + 200); // Ensure padding
canvasHeight = max(canvasHeight, maxY + 200); // Ensure padding
canvasWidth = newWidth;
canvasHeight = newHeight;
});
// Log the updated canvas size for debugging
print("Max X: $maxX, Max Y: $maxY");
print("Updated canvas size: $canvasWidth x $canvasHeight");
}
@ -208,9 +219,11 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
position: space.position,
isHovered: space.isHovered,
onPanUpdate: (int index, Offset delta) {
debugPrint("Check it works");
setState(() {
spaces[index].position += delta;
});
updateCanvasSize();
},
onHoverChanged:
(int index, bool isHovered) {
@ -255,8 +268,6 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
builder: (BuildContext context) {
return CreateSpaceDialog(
onCreateSpace: (String name, String icon) {
updateCanvasSize();
setState(() {
// Set the first space in the center or use passed position
Offset centerPosition = position ??
@ -269,6 +280,7 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
SpaceData newSpace =
SpaceData(name: name, icon: icon, position: centerPosition);
spaces.add(newSpace);
updateCanvasSize();
// Add connection for down-button
if (parentIndex != null && direction != null) {

View File

@ -26,6 +26,7 @@ class SpaceCardWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onPanUpdate: (details) {
// Call the provided callback to update the position
onPanUpdate(index, details.delta);