仪表盘 优化

This commit is contained in:
mmc
2026-03-04 13:42:39 +08:00
parent 2aa5846308
commit ab9e69705d

View File

@@ -848,7 +848,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> {
} }
} }
// ====================== 圆形仪表盘绘制器(匹配目标样式) ====================== // ====================== 圆形仪表盘绘制器(修正指针样式) ======================
class CircularGaugePainter extends CustomPainter { class CircularGaugePainter extends CustomPainter {
final double value; final double value;
final double maxValue; final double maxValue;
@@ -922,25 +922,43 @@ class CircularGaugePainter extends CustomPainter {
} }
} }
// 4. 绘制指针 // 4. 计算指针角度
final needleAngle = 135 * math.pi / 180 + 270 * math.pi / 180 * progressRatio; final needleAngle = 135 * math.pi / 180 + 270 * math.pi / 180 * progressRatio;
// 5. 绘制三角形指针(细尖角指向刻度,宽底边在中心)
final needlePaint = Paint() final needlePaint = Paint()
..color = Colors.grey.shade400 ..color = Colors.grey.shade600
..style = PaintingStyle.fill; ..style = PaintingStyle.fill;
// 指针形状(三角形) // 调整三角形顶点和底边位置:细尖角指向刻度,宽底边在中心
final needlePath = Path() final needlePath = Path()
..moveTo(center.dx, center.dy) // 1. 移动画笔到指针的细尖角(指向刻度的一端)
..lineTo(center.dx + (radius - 20) * math.cos(needleAngle - 0.02), center.dy + (radius - 20) * math.sin(needleAngle - 0.02)) ..moveTo(center.dx + (radius - 6) * math.cos(needleAngle), center.dy + (radius - 6) * math.sin(needleAngle))
..lineTo(center.dx + (radius - 20) * math.cos(needleAngle + 0.02), center.dy + (radius - 20) * math.sin(needleAngle + 0.02)) // 2. 绘制第一条边:从尖角到中心左侧的底边端点
..lineTo(
center.dx + 8 * math.cos(needleAngle - math.pi / 2), // 中心左侧8px
center.dy + 8 * math.sin(needleAngle - math.pi / 2),
)
// 3. 绘制第二条边:从中心左侧端点到中心右侧的底边端点
..lineTo(
center.dx + 8 * math.cos(needleAngle + math.pi / 2), // 中心右侧8px
center.dy + 8 * math.sin(needleAngle + math.pi / 2),
)
// 4. 闭合路径:回到尖角,形成三角形
..close(); ..close();
canvas.drawPath(needlePath, needlePaint); canvas.drawPath(needlePath, needlePaint);
// 5. 绘制指针中心圆点 //// 6. 绘制指针中心圆点(可选,增强视觉效果)
final centerDotPaint = Paint() //final centerDotPaint = Paint()
..color = Colors.grey.shade400 // ..color = Colors.white
// ..style = PaintingStyle.fill;
//canvas.drawCircle(center, 4, centerDotPaint);
// 内层小圆点增加层次感
final innerDotPaint = Paint()
..color = Colors.white
..style = PaintingStyle.fill; ..style = PaintingStyle.fill;
canvas.drawCircle(center, 6, centerDotPaint); canvas.drawCircle(center, 5, innerDotPaint);
} }
@override @override