keyboard_tutorial_page.dart 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:keyboard/base/base_page.dart';
  5. import 'package:keyboard/resource/colors.gen.dart';
  6. import 'package:keyboard/resource/string.gen.dart';
  7. import 'package:keyboard/router/app_pages.dart';
  8. import 'package:lottie/lottie.dart';
  9. import '../../resource/assets.gen.dart';
  10. import '../../utils/status_bar_util.dart';
  11. import '../../widget/app_lifecycle_widget.dart';
  12. import '../../widget/gradient_btn.dart';
  13. import 'keyboard_tutorial_controller.dart';
  14. /// 键盘使用教程-引导页
  15. class KeyboardTutorialPage extends BasePage<KeyboardTutorialController> {
  16. const KeyboardTutorialPage({super.key});
  17. static start() {
  18. Get.toNamed(RoutePath.keyboardTutorial);
  19. }
  20. /// 跳转并关闭当前页
  21. static void startAndOffMe() {
  22. Get.offNamed(RoutePath.keyboardTutorial);
  23. }
  24. @override
  25. bool immersive() {
  26. // 开启沉浸式
  27. return true;
  28. }
  29. @override
  30. backgroundColor() {
  31. return Color(0xFFF6F5FA);
  32. }
  33. @override
  34. Widget buildBody(BuildContext context) {
  35. return Scaffold(
  36. backgroundColor: backgroundColor(),
  37. body: AppLifecycleWidget(
  38. onAppLifecycleCallback: (isForeground) async {
  39. // 步骤都做完了,则跳转去键盘引导页
  40. if (await controller.checkHasComplete()) {
  41. return;
  42. }
  43. // 未完成,则每次切换到前台时,重新检查设置,更新按钮状态
  44. if (isForeground) {
  45. controller.checkSetting();
  46. }
  47. },
  48. child: Stack(
  49. children: [
  50. // 头部
  51. Positioned(left: 0, top: 0, right: 0, child: _buildHeader()),
  52. // 状态栏和标题栏
  53. Positioned(
  54. left: 0,
  55. top: 0,
  56. right: 0,
  57. child: Column(
  58. mainAxisSize: MainAxisSize.min,
  59. children: [_buildStatusBar(), _buildTopBar()],
  60. ),
  61. ),
  62. // 内容,填充剩余部分
  63. Positioned.fill(
  64. top: 235.h + StatusBarUtil.getStatusBarHeight(Get.context!),
  65. left: 0,
  66. right: 0,
  67. child: Column(children: [_buildContent()]),
  68. ),
  69. // 底部按钮
  70. Positioned(
  71. left: 0,
  72. right: 0,
  73. bottom: 0,
  74. child: _buildBottomActionBtn(),
  75. ),
  76. ],
  77. ),
  78. ),
  79. );
  80. }
  81. /// 导航栏占位
  82. Widget _buildStatusBar() {
  83. // 导航栏高度
  84. double statusBarHeight = StatusBarUtil.getStatusBarHeight(Get.context!);
  85. return Container(height: statusBarHeight);
  86. }
  87. /// 顶部栏
  88. Widget _buildTopBar() {
  89. return Container(
  90. // 宽度撑满父组件
  91. width: double.infinity,
  92. height: kToolbarHeight,
  93. // 背景颜色
  94. color: Colors.transparent,
  95. // padding: EdgeInsets.symmetric(horizontal: 16.0),
  96. child: ConstrainedBox(
  97. // 设置宽度为无限大,撑满父组件,否则Stack获取不到高度,会报错
  98. constraints: BoxConstraints(minWidth: double.infinity),
  99. child: Stack(
  100. alignment: Alignment.center,
  101. children: [
  102. // 返回按钮
  103. Positioned(
  104. left: 16.w,
  105. child: GestureDetector(
  106. onTap: controller.clickBack,
  107. child: Assets.images.iconBlackBackArrow.image(
  108. width: 24.w,
  109. height: 24.h,
  110. ),
  111. ),
  112. ),
  113. // 跳过按钮
  114. Positioned(
  115. right: 16.w,
  116. child: GestureDetector(
  117. onTap: () {
  118. controller.clickSkip();
  119. },
  120. child: Text(
  121. StringName.skip,
  122. style: TextStyle(
  123. color: ColorName.black85,
  124. fontSize: 14.sp,
  125. fontWeight: FontWeight.w500,
  126. ),
  127. ),
  128. ),
  129. ),
  130. ],
  131. ),
  132. ),
  133. );
  134. }
  135. /// 头部布局
  136. Widget _buildHeader() {
  137. return SizedBox(
  138. width: double.infinity,
  139. height: 298.h,
  140. child: Stack(
  141. alignment: Alignment.center,
  142. children: [
  143. // 头像
  144. Positioned(
  145. top: 37.5.h,
  146. bottom: 86.5.h,
  147. child: Assets.images.iconKeyboardTutorialHeader.image(
  148. height: 174.h,
  149. fit: BoxFit.cover,
  150. ),
  151. ),
  152. // 蒙版
  153. Assets.images.bgKeyboardTutorialHeaderMask.image(
  154. width: double.infinity,
  155. height: double.infinity,
  156. ),
  157. // 提示语
  158. Positioned(
  159. bottom: 60.h,
  160. child: Assets.images.iconKeyboardTutorialHeaderSlogan.image(
  161. width: 200.w,
  162. height: 73.h,
  163. ),
  164. ),
  165. ],
  166. ),
  167. );
  168. }
  169. /// 内容
  170. Widget _buildContent() {
  171. return Expanded(child: Column(children: [_buildTutorialAnimation()]));
  172. }
  173. /// 键盘设置引导动画
  174. Widget _buildTutorialAnimation() {
  175. return Lottie.asset(
  176. Assets.anim.animKeyboardTutorialSetting,
  177. repeat: true,
  178. width: 340.w,
  179. );
  180. }
  181. /// 启用键盘按钮
  182. Widget _buildEnableKeyboard() {
  183. return Obx(() {
  184. return Container(
  185. margin: EdgeInsets.symmetric(horizontal: 50.w),
  186. child: GradientTextBtn(
  187. // 是否启用,这里UI设计上,未启用时要高亮按钮,所以要取反
  188. enable: !controller.isKeyboardEnable.value,
  189. StringName.tutorialEnableKeyboardStep,
  190. onPressed: () {
  191. // 已启用,不响应点击
  192. if (controller.isKeyboardEnable.value) {
  193. return;
  194. }
  195. // 去启用键盘
  196. controller.goEnableKeyboard();
  197. },
  198. ),
  199. );
  200. });
  201. }
  202. /// 悬浮球设置按钮
  203. Widget _buildFloatingBallActionBtn() {
  204. return Obx(() {
  205. bool isKeyboardEnable = controller.isKeyboardEnable.value;
  206. bool isFloatingWindowEnable = controller.isFloatingWindowEnable.value;
  207. // 启用了键盘,但悬浮窗权限未获取到,则高亮按钮
  208. bool isHighlightBtn = isKeyboardEnable && !isFloatingWindowEnable;
  209. return Container(
  210. margin: EdgeInsets.symmetric(horizontal: 50.w),
  211. child: GradientTextBtn(
  212. enable: isHighlightBtn,
  213. StringName.tutorialEnableFloatingBallStep,
  214. onPressed: () {
  215. // 已获取,不响应点击
  216. if (controller.isFloatingWindowEnable.value) {
  217. return;
  218. }
  219. // 去启用悬浮球
  220. controller.jumpFloatingWindowSetting();
  221. },
  222. ),
  223. );
  224. });
  225. }
  226. /// 底部操作按钮
  227. Widget _buildBottomActionBtn() {
  228. return Column(
  229. children: [
  230. // 启用键盘
  231. _buildEnableKeyboard(),
  232. SizedBox(height: 20.h),
  233. // 启用悬浮球
  234. _buildFloatingBallActionBtn(),
  235. // 距离底部一定距离
  236. SizedBox(height: 25.h),
  237. ],
  238. );
  239. }
  240. }