part of ad;

class AdController extends GetxController {
  late BuildContext context;

  AdController(this.context);

  int _countdown = 5;
  late Timer _timer;

  @override
  void onInit() {
    super.onInit();
    startTime();
  }

  /// 开启定时器
  void startTime() {
    _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      if (_countdown > 0) {
        _countdown--;
        update();
      } else {
        _timer.cancel();
        // context.pushReplacementNamed(Routes.splash);
        context.goNamed(Routes.main);
      }
    });
  }

  @override
  void onClose() {
    _timer.cancel();
    super.onClose();
  }
}
