| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import 'package:keyboard/base/base_page.dart';
- import 'package:keyboard/resource/colors.gen.dart';
- import 'package:keyboard/resource/string.gen.dart';
- import 'package:keyboard/router/app_pages.dart';
- import 'package:lottie/lottie.dart';
- import '../../resource/assets.gen.dart';
- import '../../utils/status_bar_util.dart';
- import '../../widget/app_lifecycle_widget.dart';
- import '../../widget/gradient_btn.dart';
- import 'keyboard_tutorial_controller.dart';
- /// 键盘使用教程-引导页
- class KeyboardTutorialPage extends BasePage<KeyboardTutorialController> {
- const KeyboardTutorialPage({super.key});
- static start() {
- Get.toNamed(RoutePath.keyboardTutorial);
- }
- /// 跳转并关闭当前页
- static void startAndOffMe() {
- Get.offNamed(RoutePath.keyboardTutorial);
- }
- @override
- bool immersive() {
- // 开启沉浸式
- return true;
- }
- @override
- backgroundColor() {
- return Color(0xFFF6F5FA);
- }
- @override
- Widget buildBody(BuildContext context) {
- return Scaffold(
- backgroundColor: backgroundColor(),
- body: AppLifecycleWidget(
- onAppLifecycleCallback: (isForeground) async {
- // 步骤都做完了,则跳转去键盘引导页
- if (await controller.checkHasComplete()) {
- return;
- }
- // 未完成,则每次切换到前台时,重新检查设置,更新按钮状态
- if (isForeground) {
- controller.checkSetting();
- }
- },
- child: Stack(
- children: [
- // 头部
- Positioned(left: 0, top: 0, right: 0, child: _buildHeader(context)),
- // 状态栏和标题栏
- Positioned(
- left: 0,
- top: 0,
- right: 0,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [_buildStatusBar(), _buildTopBar()],
- ),
- ),
- // 内容,填充剩余部分
- Positioned.fill(
- top: 170.h + StatusBarUtil.getStatusBarHeight(Get.context!),
- left: 0,
- right: 0,
- child: Column(children: [_buildContent()]),
- ),
- // 底部按钮
- Positioned(
- left: 0,
- right: 0,
- bottom: 0,
- child: _buildBottomActionBtn(),
- ),
- ],
- ),
- ),
- );
- }
- /// 导航栏占位
- Widget _buildStatusBar() {
- // 导航栏高度
- double statusBarHeight = StatusBarUtil.getStatusBarHeight(Get.context!);
- return Container(height: statusBarHeight);
- }
- /// 顶部栏
- Widget _buildTopBar() {
- return Container(
- // 宽度撑满父组件
- width: double.infinity,
- height: kToolbarHeight,
- // 背景颜色
- color: Colors.transparent,
- // padding: EdgeInsets.symmetric(horizontal: 16.0),
- child: ConstrainedBox(
- // 设置宽度为无限大,撑满父组件,否则Stack获取不到高度,会报错
- constraints: BoxConstraints(minWidth: double.infinity),
- child: Stack(
- alignment: Alignment.center,
- children: [
- // 返回按钮
- Positioned(
- left: 16.w,
- child: GestureDetector(
- onTap: controller.clickBack,
- child: Assets.images.iconBlackBackArrow.image(
- width: 24.w,
- height: 24.h,
- ),
- ),
- ),
- // 视频教程按钮
- Positioned(
- right: 16.w,
- child: Visibility(
- visible: false,
- child: GestureDetector(
- onTap: () {
- controller.clickTutorialVideo();
- },
- child: Text(
- StringName.keyboardTutorialVideo,
- style: TextStyle(
- color: ColorName.black85,
- fontSize: 14.sp,
- fontWeight: FontWeight.w500,
- // 下划线
- decoration: TextDecoration.underline,
- // 下划线颜色
- decorationColor: ColorName.black85,
- // 下划线粗细
- decorationThickness: 1.0,
- ),
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- );
- }
- /// 头部布局
- Widget _buildHeader(BuildContext context) {
- return SizedBox(
- width: double.infinity,
- height: 298.h,
- child: Stack(
- alignment: Alignment.center,
- children: [
- // 头像
- Positioned(
- top: 37.5.h,
- bottom: 86.5.h,
- child: Assets.images.iconKeyboardTutorialHeader.image(
- height: 174.h,
- fit: BoxFit.cover,
- ),
- ),
- // 蒙版
- Assets.images.bgKeyboardTutorialHeaderMask.image(
- width: double.infinity,
- height: double.infinity,
- ),
- // 提示语
- Positioned(
- top: 70.h + StatusBarUtil.getStatusBarHeight(context),
- child: Assets.images.iconKeyboardTutorialHeaderSlogan.image(
- width: 200.w,
- height: 73.h,
- ),
- ),
- ],
- ),
- );
- }
- /// 内容
- Widget _buildContent() {
- return Expanded(child: Column(children: [_buildTutorialAnimation()]));
- }
- /// 键盘设置引导动画
- Widget _buildTutorialAnimation() {
- return Lottie.asset(
- Assets.anim.animKeyboardTutorialSetting,
- repeat: true,
- width: 340.w,
- );
- }
- /// 启用键盘按钮
- Widget _buildEnableKeyboard() {
- return Obx(() {
- return Container(
- margin: EdgeInsets.symmetric(horizontal: 50.w),
- child: GradientTextBtn(
- // 是否启用,这里UI设计上,未启用时要高亮按钮,所以要取反
- enable: !controller.isKeyboardEnable.value,
- StringName.tutorialEnableKeyboardStep,
- onPressed: () {
- // 已启用,不响应点击
- if (controller.isKeyboardEnable.value) {
- return;
- }
- // 去启用键盘
- controller.goEnableKeyboard();
- },
- ),
- );
- });
- }
- /// 悬浮球设置按钮
- Widget _buildFloatingBallActionBtn() {
- return Obx(() {
- bool isKeyboardEnable = controller.isKeyboardEnable.value;
- bool isFloatingWindowEnable = controller.isFloatingWindowEnable.value;
- // 启用了键盘,但悬浮窗权限未获取到,则高亮按钮
- bool isHighlightBtn = isKeyboardEnable && !isFloatingWindowEnable;
- return Container(
- margin: EdgeInsets.symmetric(horizontal: 50.w),
- child: GradientTextBtn(
- enable: isHighlightBtn,
- StringName.tutorialEnableFloatingBallStep,
- onPressed: () {
- // 已获取,不响应点击
- if (controller.isFloatingWindowEnable.value) {
- return;
- }
- // 去启用悬浮球
- controller.jumpFloatingWindowSetting();
- },
- ),
- );
- });
- }
- /// 底部操作按钮
- Widget _buildBottomActionBtn() {
- return Column(
- children: [
- // 启用键盘
- _buildEnableKeyboard(),
- SizedBox(height: 20.h),
- // 启用悬浮球
- _buildFloatingBallActionBtn(),
- // 距离底部一定距离
- SizedBox(height: 25.h),
- ],
- );
- }
- }
|