所以我有一个自定义Map4x3,这是我想做的:当我点击两个不同的正方形时,它会显示一条从正方形1到正方形2的线(像折线一样)。
我还没有找到实现这一点的解决方案
请帮帮我你对如何实现这一点有什么建议吗?是否有任何推荐的库来完成此任务?
下面是我使用custompaint手工定制的代码:
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Center(
child: Image.asset(
'assets/Sơ đồ mô phỏng.png',
height: 300,
),
),
CustomPaint(
painter: MyPainter(),
),
Positioned(
top: 50,
left: 10,
child: IconButton(
onPressed: () {},
icon: const Icon(
Icons.map,
size: 35,
),
),
),
Positioned(
top: 100,
left: 10,
child: IconButton(
onPressed: () {},
icon: const Icon(
Icons.pattern_sharp,
size: 35,
),
),
),
Positioned(
top: 150,
left: 10,
child: IconButton(
onPressed: () {},
icon: const Icon(
Icons.location_on,
size: 35,
),
),
)
],
),
);
}
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
const p1 = Offset(165, 100);
const p2 = Offset(165, 135);
final paint1 = Paint()
..color = Colors.black
..strokeJoin
..strokeWidth = 3;
const p3 = Offset(165, 135);
const p4 = Offset(490, 135);
final paint2 = Paint()
..color = Colors.black
..strokeWidth = 3;
const p5 = Offset(490, 100);
const p6 = Offset(490, 135);
final paint3 = Paint()
..color = Colors.black
..strokeWidth = 3;
canvas.drawLine(p1, p2, paint1);
canvas.drawLine(p3, p4, paint2);
canvas.drawLine(p5, p6, paint3);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
1条答案
按热度按时间ohfgkhjo1#
我解决了这里就是解决方案
这里这是另一个版本来画多线