1+ import 'package:cookethflow/core/widgets/painters/connector_painter.dart' ;
12import 'package:cookethflow/models/connection.dart' ;
23import 'package:cookethflow/providers/workspace_provider.dart' ;
34import 'package:flutter/material.dart' ;
@@ -37,122 +38,4 @@ class Connector extends StatelessWidget {
3738 },
3839 );
3940 }
40- }
41-
42- class ConnectorPainter extends CustomPainter {
43- final ConnectionPoint connectionPoint;
44- final bool isHovered;
45- final Color color;
46-
47- ConnectorPainter ({
48- required this .connectionPoint,
49- required this .isHovered,
50- required this .color,
51- });
52-
53- @override
54- void paint (Canvas canvas, Size size) {
55- final paint = Paint ()
56- ..color = color
57- ..style = isHovered ? PaintingStyle .fill : PaintingStyle .stroke
58- ..strokeWidth = 2.0 ;
59-
60- final path = Path ();
61- // final radius = 4.0; // Radius for rounded corners
62- // final arrowSize = size.width * 0.4; // Size of the arrow part
63-
64- switch (connectionPoint) {
65- case ConnectionPoint .top:
66- // Start from bottom-left with rounded corner
67- path.moveTo (size.width * 0.2 , size.height * 0.6 );
68- // Line to middle-top
69- path.lineTo (size.width * 0.5 , size.height * 0.2 );
70- // Line to bottom-right
71- path.lineTo (size.width * 0.8 , size.height * 0.6 );
72-
73- // Create rounded corners using quadratic bezier curves
74- path.quadraticBezierTo (
75- size.width * 0.8 , size.height * 0.7 ,
76- size.width * 0.7 , size.height * 0.7 ,
77- );
78- // Bottom line
79- path.lineTo (size.width * 0.3 , size.height * 0.7 );
80- // Final rounded corner
81- path.quadraticBezierTo (
82- size.width * 0.2 , size.height * 0.7 ,
83- size.width * 0.2 , size.height * 0.6 ,
84- );
85- break ;
86-
87- case ConnectionPoint .bottom:
88- // Rotate the top arrow 180 degrees
89- canvas.translate (size.width / 2 , size.height / 2 );
90- canvas.rotate (3.14159 );
91- canvas.translate (- size.width / 2 , - size.height / 2 );
92-
93- path.moveTo (size.width * 0.2 , size.height * 0.6 );
94- path.lineTo (size.width * 0.5 , size.height * 0.2 );
95- path.lineTo (size.width * 0.8 , size.height * 0.6 );
96- path.quadraticBezierTo (
97- size.width * 0.8 , size.height * 0.7 ,
98- size.width * 0.7 , size.height * 0.7 ,
99- );
100- path.lineTo (size.width * 0.3 , size.height * 0.7 );
101- path.quadraticBezierTo (
102- size.width * 0.2 , size.height * 0.7 ,
103- size.width * 0.2 , size.height * 0.6 ,
104- );
105- break ;
106-
107- case ConnectionPoint .left:
108- // Rotate the top arrow 270 degrees
109- canvas.translate (size.width / 2 , size.height / 2 );
110- canvas.rotate (- 1.5708 );
111- canvas.translate (- size.width / 2 , - size.height / 2 );
112-
113- path.moveTo (size.width * 0.2 , size.height * 0.6 );
114- path.lineTo (size.width * 0.5 , size.height * 0.2 );
115- path.lineTo (size.width * 0.8 , size.height * 0.6 );
116- path.quadraticBezierTo (
117- size.width * 0.8 , size.height * 0.7 ,
118- size.width * 0.7 , size.height * 0.7 ,
119- );
120- path.lineTo (size.width * 0.3 , size.height * 0.7 );
121- path.quadraticBezierTo (
122- size.width * 0.2 , size.height * 0.7 ,
123- size.width * 0.2 , size.height * 0.6 ,
124- );
125- break ;
126-
127- case ConnectionPoint .right:
128- // Rotate the top arrow 90 degrees
129- canvas.translate (size.width / 2 , size.height / 2 );
130- canvas.rotate (1.5708 );
131- canvas.translate (- size.width / 2 , - size.height / 2 );
132-
133- path.moveTo (size.width * 0.2 , size.height * 0.6 );
134- path.lineTo (size.width * 0.5 , size.height * 0.2 );
135- path.lineTo (size.width * 0.8 , size.height * 0.6 );
136- path.quadraticBezierTo (
137- size.width * 0.8 , size.height * 0.7 ,
138- size.width * 0.7 , size.height * 0.7 ,
139- );
140- path.lineTo (size.width * 0.3 , size.height * 0.7 );
141- path.quadraticBezierTo (
142- size.width * 0.2 , size.height * 0.7 ,
143- size.width * 0.2 , size.height * 0.6 ,
144- );
145- break ;
146- }
147-
148- path.close ();
149- canvas.drawPath (path, paint);
150- }
151-
152- @override
153- bool shouldRepaint (ConnectorPainter oldDelegate) {
154- return oldDelegate.connectionPoint != connectionPoint ||
155- oldDelegate.isHovered != isHovered ||
156- oldDelegate.color != color;
157- }
158- }
41+ }
0 commit comments