| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 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 '../../data/consts/constants.dart';
- import '../../resource/assets.gen.dart';
- @injectable
- class IntroController extends BaseController {
- final tag = "IntroController";
- Rx<PageController> pageController = PageController().obs;
- var currentPage = 0.obs;
- Timer? _autoPageTimer;
- IntroController();
- final List<PageBean> pageList = [
- PageBean(
- 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,
- ),
- ),
- ],
- ),
- ),
- Assets.anim.animIntroFirstData,
- ),
- PageBean(SizedBox(), Assets.anim.animIntroSecondData),
- ];
- @override
- void onInit() {
- super.onInit();
- setFirstIntro(false);
- }
- @override
- void onReady() {
- super.onReady();
- _resetTimer();
- }
- void _resetTimer() {
- _autoPageTimer?.cancel();
- _autoPageTimer = Timer.periodic(const Duration(seconds: 3), (timer) {
- swiperIntro();
- });
- }
- void swiperIntro() {
- if (currentPage.value == pageList.length - 1) {
- pageController.value.jumpToPage(0);
- } else {
- // 跳转到下一页
- pageController.value.nextPage(
- duration: const Duration(milliseconds: 500),
- curve: Curves.easeInOut,
- );
- currentPage.value++;
- }
- }
- void onPageChanged(int index) {
- currentPage.value = index;
- _resetTimer();
- }
- void clickLogin() {
- Timer(const Duration(milliseconds: 500), () {
- LoginDialog.show();
- });
- }
- void clickCustomButton() {
- Timer(const Duration(milliseconds: 500), () {
- NewUserPage.start();
- });
- }
- @override
- void onClose() {
- super.onClose();
- _autoPageTimer?.cancel();
- }
- }
- class PageBean {
- Widget title;
- String animUrl;
- PageBean(this.title, this.animUrl);
- }
|