The problem is I have an web app with the below image and every blue point in that image i clickable by adding tag and detecting the coordinates on each point to assign a javascript function..
图像
我想用flutter开发这个屏幕,flutter中有这个功能吗?
请注意,我尝试过,但没有运气!
Widget build(BuildContext context) {
return CustomPaint(
painter: MultiClickableShapePainter(),
child: Stack(
children: [
Image.asset('assets/CarInspector.png'),
InkWell(
onTap: () {
print('by');
},
),
InkWell(
onTap: () {
print('hi');
},
),
],
),
);
}
class MultiClickableShapePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
// Draw the first clickable shape on the canvas
Paint paint1 = Paint()..color = Colors.red;
Path path1 = Path();
path1.addRect(const Rect.fromLTRB(150, 150, 250, 400));
canvas.drawPath(path1, paint1);
// Draw the second clickable shape on the canvas
Paint paint2 = Paint()..color = Colors.blue;
Path path2 = Path();
path2.addRect(const Rect.fromLTRB(75, 75, 130, 200));
canvas.drawPath(path2, paint2);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
有什么建议和解决办法吗?
2条答案
按热度按时间fxnxkyjh1#
尝试在
Stack
中使用Positioned
来定位小圆将
Positioned
的child
放入InkWell
中方法
代码
输出:
fae0ux8s2#
InkWell
小工具有一个child
属性,你可以把你的Image
小工具放在那里,它将是可点击的!