From 4a9d99d7b020040dc97d74f7e8096eccf050246e Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Thu, 21 Nov 2024 19:36:16 +0400 Subject: [PATCH] fixed moving space on selecting space --- .../widgets/community_structure_widget.dart | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/pages/spaces_management/widgets/community_structure_widget.dart b/lib/pages/spaces_management/widgets/community_structure_widget.dart index a6a679f4..cdfb3345 100644 --- a/lib/pages/spaces_management/widgets/community_structure_widget.dart +++ b/lib/pages/spaces_management/widgets/community_structure_widget.dart @@ -44,6 +44,7 @@ class _CommunityStructureAreaState extends State { List connections = []; late TextEditingController _nameController; bool isEditingName = false; + late TransformationController _transformationController; @override void initState() { @@ -54,11 +55,18 @@ class _CommunityStructureAreaState extends State { _nameController = TextEditingController( text: widget.selectedCommunity?.name ?? '', ); + _transformationController = TransformationController(); + if (widget.selectedSpace != null) { + WidgetsBinding.instance.addPostFrameCallback((_) { + _moveToSpace(widget.selectedSpace!); + }); + } } @override void dispose() { _nameController.dispose(); + _transformationController.dispose(); super.dispose(); } @@ -73,6 +81,12 @@ class _CommunityStructureAreaState extends State { _adjustCanvasSizeForSpaces(); }); } + + if (widget.selectedSpace != oldWidget.selectedSpace && widget.selectedSpace != null) { + WidgetsBinding.instance.addPostFrameCallback((_) { + _moveToSpace(widget.selectedSpace!); + }); + } } @override @@ -97,6 +111,7 @@ class _CommunityStructureAreaState extends State { children: [ if (visibleSpaces.isNotEmpty) InteractiveViewer( + transformationController: _transformationController, boundaryMargin: EdgeInsets.all(500), minScale: 0.5, maxScale: 3.0, @@ -528,4 +543,16 @@ class _CommunityStructureAreaState extends State { connection.endSpace.status == SpaceStatus.deleted; }); } + + void _moveToSpace(SpaceModel space) { + final double viewportWidth = MediaQuery.of(context).size.width; + final double viewportHeight = MediaQuery.of(context).size.height; + + final double dx = -space.position.dx + (viewportWidth / 2) - 400; + final double dy = -space.position.dy + (viewportHeight / 2) - 350; + + _transformationController.value = Matrix4.identity() + ..translate(dx, dy) + ..scale(1.2); + } }