Get rotating widget degree with GestureDetector

115 Views Asked by At

I want to create knob widget so users can rotate it forward and backward(reverse). I've managed to make it work by using GestureDetector. The only problem is how to know the knob position, I've tried that code but it not working and every time the results are different.

GestureDetector(
  onPanUpdate: (DragUpdateDetails details) {
    final Offset center = Offset(constraints.maxWidth / 2, constraints.maxHeight / 2);
    final offset = details.globalPosition;

    // Calculate the angle in radians
    final double radians = math.atan2(offset.dy - center.dy, offset.dx - center.dx);

    // Convert radians to degrees
    final double degrees = radians * (180 / math.pi);

    // Handle the calculated degrees (update UI, perform actions etc.)
    print("Angle: $degrees degrees"); // Every time the results are different
  }
),
0

There are 0 best solutions below