fixed moving space on selecting space

This commit is contained in:
hannathkadher
2024-11-21 19:36:16 +04:00
parent 9239116773
commit 4a9d99d7b0

View File

@ -44,6 +44,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
List<Connection> connections = [];
late TextEditingController _nameController;
bool isEditingName = false;
late TransformationController _transformationController;
@override
void initState() {
@ -54,11 +55,18 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
_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<CommunityStructureArea> {
_adjustCanvasSizeForSpaces();
});
}
if (widget.selectedSpace != oldWidget.selectedSpace && widget.selectedSpace != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_moveToSpace(widget.selectedSpace!);
});
}
}
@override
@ -97,6 +111,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
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<CommunityStructureArea> {
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);
}
}