Files
flutterApp/lib/features/home/presentation/widgets/map/CenterLocation.dart
2026-02-25 20:36:46 +08:00

45 lines
1.2 KiB
Dart

import 'package:flutter/material.dart';
class CrosshairPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
// 十字中心坐标(精准对齐容器中心)
final centerX = size.width / 2;
final centerY = size.height / 2;
// 十字画笔样式(红色醒目,匹配原有定位标风格)
final paint = Paint()
..color = Colors.red
..strokeWidth =
2.0 // 十字线条宽度
..strokeCap = StrokeCap.round; // 线条端点圆润,更美观
// ========== 绘制水平横线(─) ==========
canvas.drawLine(
Offset(0, centerY), // 左端点
Offset(size.width, centerY), // 右端点
paint,
);
// ========== 绘制垂直竖线(│) ==========
canvas.drawLine(
Offset(centerX, 0), // 上端点
Offset(centerX, size.height), // 下端点
paint,
);
// 可选:中心小圆点(强化中心定位)
final centerDotPaint = Paint()
..color = Colors.white
..style = PaintingStyle.fill;
canvas.drawCircle(
Offset(centerX, centerY),
1.5, // 中心圆点半径
centerDotPaint,
);
}
@override
bool shouldRepaint(covariant CrosshairPainter oldDelegate) => false;
}