From bb13d333399aadbf131b14edefb65a6370de4c53 Mon Sep 17 00:00:00 2001 From: Marco Bavagnoli Date: Sat, 13 Apr 2024 13:56:57 +0200 Subject: [PATCH] center element on the given position --- README.md | 1 - example/lib/main.dart | 12 ++++++------ lib/src/elements/flow_element.dart | 9 +++++++-- lib/src/flow_chart.dart | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a45011a..748c436 100755 --- a/README.md +++ b/README.md @@ -36,7 +36,6 @@ FlowChart( onElementPressed: (context, element) {}, onHandlerPressed: (context, position, handler, element) {}, onHandlerLongPressed: (context, position, handler, element) {}, - on ) ``` diff --git a/example/lib/main.dart b/example/lib/main.dart index 9a78f41..7af537f 100755 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -249,7 +249,7 @@ class _MyHomePageState extends State { onPressed: () { dashboard.addElement( FlowElement( - position: position - const Offset(40, 40), + position: position, size: const Size(80, 80), text: '${dashboard.elements.length}', handlerSize: 25, @@ -268,7 +268,7 @@ class _MyHomePageState extends State { label: const Text('Add rect'), onPressed: () { dashboard.addElement(FlowElement( - position: position - const Offset(50, 25), + position: position, size: const Size(100, 50), text: '${dashboard.elements.length}', handlerSize: 25, @@ -285,7 +285,7 @@ class _MyHomePageState extends State { label: const Text('Add oval'), onPressed: () { dashboard.addElement(FlowElement( - position: position - const Offset(50, 25), + position: position, size: const Size(100, 50), text: '${dashboard.elements.length}', handlerSize: 25, @@ -302,7 +302,7 @@ class _MyHomePageState extends State { label: const Text('Add parallelogram'), onPressed: () { dashboard.addElement(FlowElement( - position: position - const Offset(50, 25), + position: position, size: const Size(100, 50), text: '${dashboard.elements.length}', handlerSize: 25, @@ -317,7 +317,7 @@ class _MyHomePageState extends State { label: const Text('Add hexagon'), onPressed: () { dashboard.addElement(FlowElement( - position: position - const Offset(50, 25), + position: position, size: const Size(150, 100), text: '${dashboard.elements.length}', handlerSize: 25, @@ -334,7 +334,7 @@ class _MyHomePageState extends State { label: const Text('Add storage'), onPressed: () { dashboard.addElement(FlowElement( - position: position - const Offset(50, 25), + position: position, size: const Size(100, 150), text: '${dashboard.elements.length}', handlerSize: 25, diff --git a/lib/src/elements/flow_element.dart b/lib/src/elements/flow_element.dart index fa6dbee..8f03c3b 100755 --- a/lib/src/elements/flow_element.dart +++ b/lib/src/elements/flow_element.dart @@ -73,7 +73,7 @@ class FlowElement extends ChangeNotifier { bool isResizing; FlowElement({ - this.position = Offset.zero, + position = Offset.zero, this.size = Size.zero, this.text = '', this.textColor = Colors.black, @@ -95,7 +95,12 @@ class FlowElement extends ChangeNotifier { next, }) : next = next ?? [], id = const Uuid().v4(), - isResizing = false; + isResizing = false, + position = position - + Offset( + size.width / 2 + handlerSize / 2, + size.height / 2 + handlerSize / 2, + ); @override String toString() { diff --git a/lib/src/flow_chart.dart b/lib/src/flow_chart.dart index 4d7c684..28d720a 100755 --- a/lib/src/flow_chart.dart +++ b/lib/src/flow_chart.dart @@ -178,10 +178,10 @@ class _FlowChartState extends State { Positioned.fill( child: GestureDetector( onTapDown: (details) { - tapDownPos = details.globalPosition; + tapDownPos = details.localPosition; }, onSecondaryTapDown: (details) { - secondaryTapDownPos = details.globalPosition; + secondaryTapDownPos = details.localPosition; }, onTap: widget.onDashboardTapped == null ? null