startCountDown method

void startCountDown()

倒计时

Implementation

void startCountDown() {
  if (isClosed || isCountingDown.value) return;
  reset();
  isCountingDown.value = true;
  _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
    //退到后台的时候,tick会缓存过去的时间
    countDownTime.value = totalDuration - timer.tick;
    if (timer.tick > totalDuration || countDownTime.value == 0 || isClosed) {
      isCountingDown.value = false;
      timer.cancel();
      onStop?.call();
      return;
    }
  });
}