Wallpaper-Genie/lib/page/splash/splash_controller.dart
xuhang-x 3bf5f4fa10 1
2024-07-26 18:41:05 +08:00

42 lines
772 B
Dart

import 'dart:async';
import 'package:get/get.dart';
import 'package:wallpaperx/config/applovin.dart';
import 'package:wallpaperx/routes/app_pages.dart';
class SplashController extends GetxController {
Timer? _timer;
@override
void onInit() {
super.onInit();
ApplovinUtil().initializeInterstitialAds(onGoHomeTap: toIndex);
_startTimer();
}
@override
void onClose() {
_stopTimer();
super.onClose();
}
/// 开始定时器
void _startTimer() {
_timer = Timer.periodic(const Duration(seconds: 10), (Timer t) {
toIndex();
});
}
/// 停止定时器
void _stopTimer() {
_timer?.cancel();
_timer = null;
}
/// 打开首页
void toIndex() {
_stopTimer();
Get.offAndToNamed(AppPages.home);
}
}