Page MenuHomec4science

arrow.dart
No OneTemporary

File Metadata

Created
Fri, May 31, 22:40

arrow.dart

import 'package:flutter/material.dart';
import 'package:arrow_path/arrow_path.dart';
import 'package:student/model/Cellulo.dart';
class Arrow extends CustomPainter {
// <-- CustomPainter class
var celluloxPosition;
var celluloyPosition;
var coeffScreenMapWidth;
var coeffScreenMapHeight;
double directionx;
double directiony;
Offset celluloyM;
Offset celluloxM;
Arrow(this.celluloxPosition, this.celluloyPosition, this.coeffScreenMapWidth,
this.coeffScreenMapHeight, this.directionx, this.directiony) {
celluloxM = Offset(celluloxPosition[0] * coeffScreenMapWidth,
celluloxPosition[1] * coeffScreenMapHeight);
celluloyM = Offset(celluloyPosition[0] * coeffScreenMapWidth,
celluloyPosition[1] * coeffScreenMapHeight);
if (directionx < -40)
directionx = -1;
else if (directionx > 40)
directionx = 1;
else {
directionx = 0;
}
if (directiony < -40)
directiony = -1;
else if (directiony > 40)
directiony = 1;
else {
directiony = 0;
}
}
@override
void paint(Canvas canvas, Size size) {
Path path;
Paint paintblue = Paint()
..color = Colors.blue
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round
..strokeWidth = 3.0;
Paint paintRed = Paint()
..color = Colors.red
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round
..strokeWidth = 3.0;
path = Path();
path.moveTo(celluloxM.dx - 20, celluloxM.dy - 20);
path.relativeCubicTo(0, 0, 0, 0, directionx.toDouble() * 40, 0);
path = ArrowPath.make(path: path);
canvas.drawPath(path, paintRed);
path.moveTo(celluloyM.dx + 30, celluloyM.dy);
path.relativeCubicTo(0, 0, 0, 0, 0, directiony.toDouble() * 40);
path = ArrowPath.make(path: path);
canvas.drawPath(path, paintblue);
//canvas.drawLine(p1, p2, paint);
}
@override
bool shouldRepaint(CustomPainter old) {
return false;
}
}

Event Timeline