如何使用CustomPainter绘制矩形画布视图

时间:2019-04-01 08:26:05

标签: flutter

我正在尝试为通话记录绘制画布矩形线。如何使用customPainter绘制它?有更好的方法吗?

enter image description here

1 个答案:

答案 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()),
    ),
  ),
),