| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import 'dart:async';
- import 'dart:io';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:get/get.dart';
- import 'package:keyboard/base/base_controller.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:keyboard/data/repository/account_repository.dart';
- import 'package:keyboard/module/login/login_page.dart';
- import 'package:keyboard/module/main/main_controller.dart';
- import 'package:keyboard/utils/toast_util.dart';
- import '../../data/consts/constants.dart';
- import '../../data/consts/event_report.dart';
- import '../../handler/event_handler.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';
- import '../../widget/platform_util.dart';
- @injectable
- class IntroController extends BaseController {
- final tag = "IntroController";
- Rx<PageController> pageController = PageController().obs;
- var currentPage = 0.obs;
- Timer? _autoPageTimer;
- late Worker _loginSubscription;
- IntroController();
- /// 页面数据列表
- final List<PageBean> pageList = [
- PageBean(
- title: () {
- return Text.rich(
- textAlign: TextAlign.center,
- TextSpan(
- children: [
- TextSpan(
- text: '想知道\n',
- style: TextStyle(
- color: Colors.black.withAlpha(153),
- fontSize: 14.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- TextSpan(
- text: 'Ta ',
- style: TextStyle(
- color: const Color(0xFF7D46FC),
- fontSize: 24.sp,
- fontWeight: FontWeight.w600,
- ),
- ),
- TextSpan(
- text: '对你到底是‘朋友’还是‘心动’?',
- style: TextStyle(
- color: Colors.black.withAlpha(153),
- fontSize: 14.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- ],
- ),
- );
- },
- animUrl: Assets.anim.animIntroFirstData,
- stayDuration: const Duration(milliseconds: 4100),
- ),
- PageBean(
- title: () {
- return const SizedBox();
- },
- animUrl: Assets.anim.animIntroSecondData,
- stayDuration: const Duration(milliseconds: 5500),
- ),
- ];
- @override
- void onInit() {
- super.onInit();
- setFirstIntro(false);
- }
- @override
- void onReady() {
- super.onReady();
- _startAutoSwitchTimer();
- Future.delayed(Duration(seconds: 3), () {
- EventHandler.report(EventId.event_01000);
- });
- // 监听登录状态
- _loginSubscription= ever(AccountRepository.getInstance().isLogin, (bool isLogin) {
- if (isLogin) {
- // 登录后跳转新用户页
- Future.delayed(const Duration(milliseconds: 300), () {
- NewUserPage.start();
- });
- }
- });
- }
- /// 开始自动切页计时
- void _startAutoSwitchTimer() {
- _autoPageTimer?.cancel();
- 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;
- _startAutoSwitchTimer();
- }
- void clickLogin() {
- Timer(const Duration(milliseconds: 500), () {
- if (AccountRepository.getInstance().isLogin.value) {
- ToastUtil.show("您已登录~");
- return;
- }
- if (PlatformUtil.isIOS) {
- LoginPage.start();
- } else {
- LoginDialog.show();
- }
- });
- EventHandler.report(EventId.event_01002);
- }
- void clickCustomButton() {
- Timer(const Duration(milliseconds: 500), () {
- NewUserPage.start();
- });
- EventHandler.report(EventId.event_01001);
- }
- void clickBack() {
- if (PlatformUtil.isAndroid) {
- SystemNavigator.pop();
- }
- exit(0);
- }
- @override
- void onClose() {
- _loginSubscription.dispose();
- _autoPageTimer?.cancel();
- super.onClose();
- }
- }
- class PageBean {
- final WidgetFunction title;
- final String animUrl;
- final Duration stayDuration; // 每页停留时间
- PageBean({
- required this.title,
- required this.animUrl,
- required this.stayDuration,
- });
- }
|