|
|
@@ -1,30 +1,28 @@
|
|
|
import 'dart:async';
|
|
|
-
|
|
|
-import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
-import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
-import 'package:injectable/injectable.dart';
|
|
|
-import 'package:keyboard/base/base_controller.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
-import 'package:keyboard/dialog/login/login_dialog.dart';
|
|
|
-import 'package:keyboard/module/new_user/new_user_page.dart';
|
|
|
+import 'package:keyboard/base/base_controller.dart';
|
|
|
+import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
import '../../data/consts/constants.dart';
|
|
|
import '../../resource/assets.gen.dart';
|
|
|
+import '../../dialog/login/login_dialog.dart';
|
|
|
+import '../../module/new_user/new_user_page.dart';
|
|
|
+import 'package:injectable/injectable.dart';
|
|
|
|
|
|
@injectable
|
|
|
class IntroController extends BaseController {
|
|
|
final tag = "IntroController";
|
|
|
- Rx<PageController> pageController = PageController().obs;
|
|
|
|
|
|
+ Rx<PageController> pageController = PageController().obs;
|
|
|
var currentPage = 0.obs;
|
|
|
-
|
|
|
Timer? _autoPageTimer;
|
|
|
|
|
|
IntroController();
|
|
|
|
|
|
+ /// 页面数据列表
|
|
|
final List<PageBean> pageList = [
|
|
|
PageBean(
|
|
|
- Text.rich(
|
|
|
+ title: Text.rich(
|
|
|
textAlign: TextAlign.center,
|
|
|
TextSpan(
|
|
|
children: [
|
|
|
@@ -55,9 +53,14 @@ class IntroController extends BaseController {
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
- Assets.anim.animIntroFirstData,
|
|
|
+ animUrl: Assets.anim.animIntroFirstData,
|
|
|
+ stayDuration: const Duration(milliseconds:4100),
|
|
|
+ ),
|
|
|
+ PageBean(
|
|
|
+ title: const SizedBox(),
|
|
|
+ animUrl: Assets.anim.animIntroSecondData,
|
|
|
+ stayDuration:const Duration(milliseconds: 5500)
|
|
|
),
|
|
|
- PageBean(SizedBox(), Assets.anim.animIntroSecondData),
|
|
|
];
|
|
|
|
|
|
@override
|
|
|
@@ -65,39 +68,39 @@ class IntroController extends BaseController {
|
|
|
super.onInit();
|
|
|
setFirstIntro(false);
|
|
|
}
|
|
|
+
|
|
|
@override
|
|
|
void onReady() {
|
|
|
super.onReady();
|
|
|
- _resetTimer();
|
|
|
+ _startAutoSwitchTimer();
|
|
|
}
|
|
|
- void _resetTimer() {
|
|
|
+
|
|
|
+ /// 开始自动切页计时
|
|
|
+ void _startAutoSwitchTimer() {
|
|
|
_autoPageTimer?.cancel();
|
|
|
- _autoPageTimer = Timer.periodic(const Duration(seconds: 3), (timer) {
|
|
|
- swiperIntro();
|
|
|
- });
|
|
|
+ final duration = pageList[currentPage.value].stayDuration;
|
|
|
+ _autoPageTimer = Timer(duration, swiperIntro);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /// 执行切页
|
|
|
void swiperIntro() {
|
|
|
if (currentPage.value == pageList.length - 1) {
|
|
|
pageController.value.jumpToPage(0);
|
|
|
-
|
|
|
+ currentPage.value = 0;
|
|
|
} else {
|
|
|
- // 跳转到下一页
|
|
|
-
|
|
|
pageController.value.nextPage(
|
|
|
duration: const Duration(milliseconds: 500),
|
|
|
curve: Curves.easeInOut,
|
|
|
);
|
|
|
currentPage.value++;
|
|
|
}
|
|
|
+ _startAutoSwitchTimer(); // 切完后,重新根据新页面设定计时
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /// 页面切换时回调
|
|
|
void onPageChanged(int index) {
|
|
|
-
|
|
|
currentPage.value = index;
|
|
|
- _resetTimer();
|
|
|
+ _startAutoSwitchTimer();
|
|
|
}
|
|
|
|
|
|
void clickLogin() {
|
|
|
@@ -114,16 +117,19 @@ class IntroController extends BaseController {
|
|
|
|
|
|
@override
|
|
|
void onClose() {
|
|
|
- super.onClose();
|
|
|
_autoPageTimer?.cancel();
|
|
|
+ super.onClose();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
class PageBean {
|
|
|
- Widget title;
|
|
|
- String animUrl;
|
|
|
-
|
|
|
- PageBean(this.title, this.animUrl);
|
|
|
+ final Widget title;
|
|
|
+ final String animUrl;
|
|
|
+ final Duration stayDuration; // 每页停留时间
|
|
|
+
|
|
|
+ PageBean({
|
|
|
+ required this.title,
|
|
|
+ required this.animUrl,
|
|
|
+ required this.stayDuration,
|
|
|
+ });
|
|
|
}
|