startCountDown method

void startCountDown()

启动倒计时Timer.

Implementation

void startCountDown() {
  if (_isActive || interval <= 0 || totalTime <= 0) return;
  _isActive = true;
  Duration duration = Duration(seconds: interval);
  _doCallback(totalTime);
  _mTimer = Timer.periodic(duration, (Timer timer) {
    int time = totalTime - interval;
    totalTime = time;
    if (time >= interval) {
      _doCallback(time);
    } else if (time == 0) {
      _doCallback(time);
      cancel();
    } else {
      timer.cancel();
      Future.delayed(Duration(seconds: time), () {
        totalTime = 0;
        _doCallback(0);
        cancel();
      });
    }
  });
}