我使用偏移量和坐标。我使用点将它们合并组合并让它们绘制一个形状,当我隐藏这个绘制的形状并再次打开它时,一条线从屏幕左上角出现在我的形状上。如何防止这种情况?
beforeafter的数据库
眼睛按钮功能
InkWell(onTap: () {
setState(() {
if (isEyeSelected) {
selectedEyeIndexes.remove(index);
showHiddenItems(index);
} else {
selectedEyeIndexes.add(index);
for (int i = 0; i < studentLabelCoordinate[index].length; i++) {
studentLabelCoordinate[index][i] = Offset.zero;
}
}
});
},
字符串
功能
void showHiddenItems(int index) {
if (imageTypeState?.toLowerCase() ==
'bitewing' ||
imageTypeState?.toLowerCase() ==
'periapical') {
for (var j = 0;
j <
studentAnswerModel!
.illnessCoordsColors![
index]
.coords!
.length;
j++) {
studentLabelCoordinate[index].add(Offset(
(studentAnswerModel!
.illnessCoordsColors![
index]
.coords![j][0] *
width!) *
widthrate *
_scale,
(studentAnswerModel!
.illnessCoordsColors![
index]
.coords![j][1] *
height!) *
_scale *
heightrate -
(deviceTopPadding!)));
}
} else {
for (var j = 0;
j <
studentAnswerModel!
.illnessCoordsColors![
index]
.coords!
.length;
j++) {
studentLabelCoordinate[index].add(Offset(
(studentAnswerModel!
.illnessCoordsColors![
index]
.coords![j][0] *
width!) *
_scale,
(studentAnswerModel!
.illnessCoordsColors![
index]
.coords![j][1] *
height! *
_scale) -
(deviceTopPadding! +
deviceBottomPadding! +
5.h)));
}
}
}
型
画家
class PathPainterStudent extends CustomPainter {
PathPainterStudent({
required this.coordinats,
required this.labelColor,
});
List<List<Offset>> coordinats;
List<String> labelColor;
@override
void paint(Canvas canvas, Size size) {
List<Path> paths = [];
for (var i = 0; i < coordinats.length; i++) {
Paint paintq = Paint()
..color = Color(int.parse(labelColor[i].replaceAll('#', '0xFF')))
..style = PaintingStyle.stroke
..strokeWidth = 2.0;
Paint paintq2 = Paint()
..color = Color(int.parse(labelColor[i].replaceAll('#', '0xFF')))
.withOpacity(0.2)
..style = PaintingStyle.fill
..strokeWidth = 2.0;
Path path = Path();
paths.add(path);
paths[i].addPolygon(coordinats[i], true);
paths[i].close();
canvas.drawPath(paths[i], paintq);
canvas.drawPath(paths[i], paintq2);
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
型
定制绘画
CustomPaint(
painter: PathPainterStudent(
coordinats: studentLabelCoordinate,
labelColor: studentLabelColor),
size: MediaQuery.of(context).size,
),
型
我把它从列表中删除,然后再把它添加到列表中。我试着在画家中玩,但没有发生。当你从外部给予一个偏移列表时,它总是把它们连接在一起。
1条答案
按热度按时间kgsdhlau1#
默认情况下,
Path
从(0, 0)
开始。在调用
Canvas.drawPath()
之前,使用Path.moveTo(x, y)
将path
移动到起始点。字符串
希望有帮助!