import 'dart:async';

class PopupTimer {
  Timer? _timer;
  int _seconds = 0;
  bool _isActive = false;
  Function(int)? onTimerTick;

  void startTimer(
      {int durationSeconds = 60,
      Function? onTimerComplete,
      Function(int)? onTimerTick}) {
    this.onTimerTick = onTimerTick;
    _isActive = true;
    _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      _seconds++;
      print(_seconds);
      onTimerTick?.call(_seconds); // 调用回调函数并传递“_seconds”值
      if (_seconds == durationSeconds) {
        stopTimer();
        onTimerComplete?.call();
      }
    });
  }

  void stopTimer() {
    _isActive = false;
    _timer?.cancel();
    _timer = null;
  }

  void resetTimer() {
    _seconds = 0;
    stopTimer();
  }
}
