intro_controller.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import 'dart:async';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:injectable/injectable.dart';
  6. import 'package:keyboard/base/base_controller.dart';
  7. import 'package:get/get.dart';
  8. import 'package:keyboard/dialog/login/login_dialog.dart';
  9. import 'package:keyboard/module/new_user/new_user_page.dart';
  10. import '../../data/consts/constants.dart';
  11. import '../../resource/assets.gen.dart';
  12. @injectable
  13. class IntroController extends BaseController {
  14. final tag = "IntroController";
  15. Rx<PageController> pageController = PageController().obs;
  16. var currentPage = 0.obs;
  17. Timer? _autoPageTimer;
  18. IntroController();
  19. final List<PageBean> pageList = [
  20. PageBean(
  21. Text.rich(
  22. textAlign: TextAlign.center,
  23. TextSpan(
  24. children: [
  25. TextSpan(
  26. text: '想知道\n',
  27. style: TextStyle(
  28. color: Colors.black.withAlpha(153),
  29. fontSize: 14.sp,
  30. fontWeight: FontWeight.w500,
  31. ),
  32. ),
  33. TextSpan(
  34. text: 'Ta ',
  35. style: TextStyle(
  36. color: const Color(0xFF7D46FC),
  37. fontSize: 24.sp,
  38. fontWeight: FontWeight.w600,
  39. ),
  40. ),
  41. TextSpan(
  42. text: '对你到底是‘朋友’还是‘心动’?',
  43. style: TextStyle(
  44. color: Colors.black.withAlpha(153),
  45. fontSize: 14.sp,
  46. fontWeight: FontWeight.w500,
  47. ),
  48. ),
  49. ],
  50. ),
  51. ),
  52. Assets.anim.animIntroFirstData,
  53. ),
  54. PageBean(SizedBox(), Assets.anim.animIntroSecondData),
  55. ];
  56. @override
  57. void onInit() {
  58. super.onInit();
  59. setFirstIntro(false);
  60. }
  61. @override
  62. void onReady() {
  63. super.onReady();
  64. _resetTimer();
  65. }
  66. void _resetTimer() {
  67. _autoPageTimer?.cancel();
  68. _autoPageTimer = Timer.periodic(const Duration(seconds: 3), (timer) {
  69. swiperIntro();
  70. });
  71. }
  72. void swiperIntro() {
  73. if (currentPage.value == pageList.length - 1) {
  74. pageController.value.jumpToPage(0);
  75. } else {
  76. // 跳转到下一页
  77. pageController.value.nextPage(
  78. duration: const Duration(milliseconds: 500),
  79. curve: Curves.easeInOut,
  80. );
  81. currentPage.value++;
  82. }
  83. }
  84. void onPageChanged(int index) {
  85. currentPage.value = index;
  86. _resetTimer();
  87. }
  88. void clickLogin() {
  89. Timer(const Duration(milliseconds: 500), () {
  90. LoginDialog.show();
  91. });
  92. }
  93. void clickCustomButton() {
  94. Timer(const Duration(milliseconds: 500), () {
  95. NewUserPage.start();
  96. });
  97. }
  98. @override
  99. void onClose() {
  100. super.onClose();
  101. _autoPageTimer?.cancel();
  102. }
  103. }
  104. class PageBean {
  105. Widget title;
  106. String animUrl;
  107. PageBean(this.title, this.animUrl);
  108. }