changed to curve line

This commit is contained in:
hannathkadher
2024-09-05 14:29:26 +04:00
parent f32076eba1
commit 17510c48f2

View File

@ -28,7 +28,7 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
// Draw lines using a CustomPaint widget // Draw lines using a CustomPaint widget
CustomPaint( CustomPaint(
size: Size.infinite, size: Size.infinite,
painter: LinePainter(connections), painter: CurvedLinePainter(connections),
), ),
Center( Center(
child: spaces.isEmpty child: spaces.isEmpty
@ -114,7 +114,7 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
if (spaces[index].isHovered) ...[ if (spaces[index].isHovered) ...[
_buildPlusButton(index, 'left', const Offset(-21, 20), screenSize), _buildPlusButton(index, 'left', const Offset(-21, 20), screenSize),
_buildPlusButton(index, 'right', const Offset(140, 20), screenSize), _buildPlusButton(index, 'right', const Offset(140, 20), screenSize),
_buildPlusButton(index, 'down', const Offset(63, 55), screenSize), _buildPlusButton(index, 'down', const Offset(63, 50), screenSize),
], ],
], ],
), ),
@ -239,10 +239,11 @@ class Connection {
} }
// Custom painter to draw lines between connected spaces // Custom painter to draw lines between connected spaces
class LinePainter extends CustomPainter {
class CurvedLinePainter extends CustomPainter {
final List<Connection> connections; final List<Connection> connections;
LinePainter(this.connections); CurvedLinePainter(this.connections);
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
@ -255,8 +256,20 @@ class LinePainter extends CustomPainter {
final start = connection.startSpace.position + Offset(75, 60); // Bottom center of the starting space final start = connection.startSpace.position + Offset(75, 60); // Bottom center of the starting space
final end = connection.endSpace.position + Offset(75, 0); // Top center of the ending space final end = connection.endSpace.position + Offset(75, 0); // Top center of the ending space
// Draw a straight line connecting the two spaces // Calculate control point for Bézier curve (to create a curve)
canvas.drawLine(start, end, paint); final controlPoint = Offset((start.dx + end.dx) / 2, start.dy + 50);
// Draw the Bézier curve
final path = Path()
..moveTo(start.dx, start.dy)
..quadraticBezierTo(controlPoint.dx, controlPoint.dy, end.dx, end.dy);
canvas.drawPath(path, paint);
// Draw small connection dots at the start and end points
final dotPaint = Paint()..color = ColorsManager.blackColor;
canvas.drawCircle(start, 5, dotPaint); // Start dot
canvas.drawCircle(end, 5, dotPaint); // End dot
} }
} }
@ -264,6 +277,4 @@ class LinePainter extends CustomPainter {
bool shouldRepaint(covariant CustomPainter oldDelegate) { bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true; return true;
} }
} }