答案 0 :(得分:0)
您需要创建一个CustomPainter
class YourRect extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
canvas.drawRect(
new Rect.fromLTRB(0.0, 0.0, 100.0, 50.0),
new Paint()..color = new Color(0xFF0099FF),
);
}
@override
bool shouldRepaint(YourRect oldDelegate) {
return false;
}
}
然后像这样使用它:
new GestureDetector(
onTap: () {
debugPrint("hello");
},
child: Container(
width: 50,
height: 50,
child: CustomPaint(
painter: (YourdrawRect()),
),
),
),