stickyHourHand method

void stickyHourHand()

Implementation

void stickyHourHand() {
  //search angle beetween all possible angles
  for (int i = 0; i < hourAngles.length; i++) {
    if (i < hourAngles.length - 1) {
      double angle1 = hourAngles[i];
      double angle2 = hourAngles[i + 1];

      if (controller.value > angle1 && controller.value < angle2) {
        //calculate current hand angle distance beetween previous and next possible angle
        double angleDistance1 = (controller.value - angle1).abs();
        double angleDistance2 = (controller.value - angle2).abs();

        //assign the closest possible angle from current hand angle
        if (angleDistance1 > angleDistance2) {
          controller
              .animateTo(angle2, duration: const Duration(milliseconds: 100))
              .whenComplete(setTime);
        } else {
          controller
              .animateTo(angle1, duration: const Duration(milliseconds: 100))
              .whenComplete(setTime);
        }

        break;
      }
    }
  }
}