keyboard_tutorial_page.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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(context)),
  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: 170.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: Visibility(
  117. visible: false,
  118. child: GestureDetector(
  119. onTap: () {
  120. controller.clickTutorialVideo();
  121. },
  122. child: Text(
  123. StringName.keyboardTutorialVideo,
  124. style: TextStyle(
  125. color: ColorName.black85,
  126. fontSize: 14.sp,
  127. fontWeight: FontWeight.w500,
  128. // 下划线
  129. decoration: TextDecoration.underline,
  130. // 下划线颜色
  131. decorationColor: ColorName.black85,
  132. // 下划线粗细
  133. decorationThickness: 1.0,
  134. ),
  135. ),
  136. ),
  137. ),
  138. ),
  139. ],
  140. ),
  141. ),
  142. );
  143. }
  144. /// 头部布局
  145. Widget _buildHeader(BuildContext context) {
  146. return SizedBox(
  147. width: double.infinity,
  148. height: 298.h,
  149. child: Stack(
  150. alignment: Alignment.center,
  151. children: [
  152. // 头像
  153. Positioned(
  154. top: 37.5.h,
  155. bottom: 86.5.h,
  156. child: Assets.images.iconKeyboardTutorialHeader.image(
  157. height: 174.h,
  158. fit: BoxFit.cover,
  159. ),
  160. ),
  161. // 蒙版
  162. Assets.images.bgKeyboardTutorialHeaderMask.image(
  163. width: double.infinity,
  164. height: double.infinity,
  165. ),
  166. // 提示语
  167. Positioned(
  168. top: 70.h + StatusBarUtil.getStatusBarHeight(context),
  169. child: Assets.images.iconKeyboardTutorialHeaderSlogan.image(
  170. width: 200.w,
  171. height: 73.h,
  172. ),
  173. ),
  174. ],
  175. ),
  176. );
  177. }
  178. /// 内容
  179. Widget _buildContent() {
  180. return Expanded(child: Column(children: [_buildTutorialAnimation()]));
  181. }
  182. /// 键盘设置引导动画
  183. Widget _buildTutorialAnimation() {
  184. return Lottie.asset(
  185. Assets.anim.animKeyboardTutorialSetting,
  186. repeat: true,
  187. width: 340.w,
  188. );
  189. }
  190. /// 启用键盘按钮
  191. Widget _buildEnableKeyboard() {
  192. return Obx(() {
  193. return Container(
  194. margin: EdgeInsets.symmetric(horizontal: 50.w),
  195. child: GradientTextBtn(
  196. // 是否启用,这里UI设计上,未启用时要高亮按钮,所以要取反
  197. enable: !controller.isKeyboardEnable.value,
  198. StringName.tutorialEnableKeyboardStep,
  199. onPressed: () {
  200. // 已启用,不响应点击
  201. if (controller.isKeyboardEnable.value) {
  202. return;
  203. }
  204. // 去启用键盘
  205. controller.goEnableKeyboard();
  206. },
  207. ),
  208. );
  209. });
  210. }
  211. /// 悬浮球设置按钮
  212. Widget _buildFloatingBallActionBtn() {
  213. return Obx(() {
  214. bool isKeyboardEnable = controller.isKeyboardEnable.value;
  215. bool isFloatingWindowEnable = controller.isFloatingWindowEnable.value;
  216. // 启用了键盘,但悬浮窗权限未获取到,则高亮按钮
  217. bool isHighlightBtn = isKeyboardEnable && !isFloatingWindowEnable;
  218. return Container(
  219. margin: EdgeInsets.symmetric(horizontal: 50.w),
  220. child: GradientTextBtn(
  221. enable: isHighlightBtn,
  222. StringName.tutorialEnableFloatingBallStep,
  223. onPressed: () {
  224. // 已获取,不响应点击
  225. if (controller.isFloatingWindowEnable.value) {
  226. return;
  227. }
  228. // 去启用悬浮球
  229. controller.jumpFloatingWindowSetting();
  230. },
  231. ),
  232. );
  233. });
  234. }
  235. /// 底部操作按钮
  236. Widget _buildBottomActionBtn() {
  237. return Column(
  238. children: [
  239. // 启用键盘
  240. _buildEnableKeyboard(),
  241. SizedBox(height: 20.h),
  242. // 启用悬浮球
  243. _buildFloatingBallActionBtn(),
  244. // 距离底部一定距离
  245. SizedBox(height: 25.h),
  246. ],
  247. );
  248. }
  249. }