如何基于Flutter中的触摸事件移动Custompainter

时间:2018-12-22 15:46:22

标签: dart flutter

我想做一个时间选择器,我已经在颤振中使用自定义绘画工具进行了时钟设计,我也使用了相同的绘画方式制作了时钟指针,但是现在我不知道如何像设置时间那样在触摸事件上移动它们。

class ClockHandsPainter extends CustomPainter{

 final Offset centerPoint;
 final double radius;
 final int degree;

 ClockHandsPainter( {this.centerPoint, this.radius, this.degree});


 @override
 void paint(Canvas canvas, Size size) {

  var paint = Paint();
  paint.strokeWidth = 2.0;
  paint.color = Colors.white;

  var calculator = Coordinate();

  final Coordinate topPointHourHand = calculator.calculateCoordinate(
    centerX: centerPoint.dx,
    centerY: centerPoint.dy,
    radius: radius,
    theta: degree
  );

  canvas.drawLine(
      Offset(centerPoint.dx, centerPoint.dy),
      Offset(topPointHourHand.dx, topPointHourHand.dy),
      paint
  );
 }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
  return true;
  }

}

我将如何检测用户是否单击了时钟并将其拖动到某个点,以便将该指针移到该点。

如建议的那样,我尝试使用GestureDetector,但无法从中获得任何帮助

GestureDetector(
                  child: CustomPaint(
                    size: Size(0.0, 0.0),
                    painter: ClockHandsPainter(
                      radius: clockRadius - 60,
                      degree: 6,
                      centerPoint: Offset(0,190)
                    ),
                  ),
                  behavior: HitTestBehavior.opaque,
                  onTap: (){
                    print("tapped");
                  },
                ),

0 个答案:

没有答案