Skip to content

Commit

Permalink
center element on the given position
Browse files Browse the repository at this point in the history
  • Loading branch information
alnitak committed Apr 13, 2024
1 parent 82a764d commit bb13d33
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ FlowChart(
onElementPressed: (context, element) {},
onHandlerPressed: (context, position, handler, element) {},
onHandlerLongPressed: (context, position, handler, element) {},
on
)
```

Expand Down
12 changes: 6 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: () {
dashboard.addElement(
FlowElement(
position: position - const Offset(40, 40),
position: position,
size: const Size(80, 80),
text: '${dashboard.elements.length}',
handlerSize: 25,
Expand All @@ -268,7 +268,7 @@ class _MyHomePageState extends State<MyHomePage> {
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,
Expand All @@ -285,7 +285,7 @@ class _MyHomePageState extends State<MyHomePage> {
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,
Expand All @@ -302,7 +302,7 @@ class _MyHomePageState extends State<MyHomePage> {
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,
Expand All @@ -317,7 +317,7 @@ class _MyHomePageState extends State<MyHomePage> {
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,
Expand All @@ -334,7 +334,7 @@ class _MyHomePageState extends State<MyHomePage> {
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,
Expand Down
9 changes: 7 additions & 2 deletions lib/src/elements/flow_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/flow_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ class _FlowChartState extends State<FlowChart> {
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
Expand Down

0 comments on commit bb13d33

Please sign in to comment.