0
点赞
收藏
分享

微信扫一扫

widget 分析1

@override
  Widget build(BuildContext context) {
    listenKeepAlive();
    return WillPopScope(
      onWillPop: _onWillPop,
      child: AiCommonScaffold(
        body: Listener(
          onPointerDown: (event) {
            final show = ref.read(resultPageController).showResultCountDown;
            if (show) {
              ref.read(resultPageController).setShowResultCountDown(false);
            }
          },
          child: Stack(
            fit: StackFit.expand,
            children: [
              Column(
                children: [
                  Container(
                    color: PracticeGlobalSetting.getInstance().eyeProtection ? const Color(0xFFFAF8DF) : Colors.white,
                    width: double.infinity,
                    height: 57,
                    child: Stack(
                      children: [
                        const Center(
                          child: Text(
                            '评测报告',
                            style: TextStyle(
                              fontSize: 17,
                              color: Color(0xff874c05),
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                        Visibility(
                          visible: !ref.watch(
                            resultPageController.select((value) => value.showScore),
                          ),
                          child: const Align(
                            alignment: Alignment.centerRight,
                            child: PracticeResultTopBar(),
                          ),
                        ),
                      ],
                    ),
                  ),
                  const Expanded(child: PracticeResultScore()),
                ],
              ),
              Visibility(
                visible: !ref.watch(
                  resultPageController.select((value) => value.showScore),
                ),
                child: Positioned(
                  top: 62,
                  right: 21,
                  child: GestureDetector(
                    onTap: () async {
                      showDialog(
                        context: context,
                        builder: (context) {
                          return const PracticeFeedbackDialog();
                        },
                      );
                    },
                    child: AiImage(
                      ImageResource.ic_audion_inaccurate,
                      fit: BoxFit.fill,
                      width: 95,
                      height: 30,
                    ),
                  ),
                ),
              ),
              Visibility(
                visible: ref.watch(
                  resultPageController.select((value) => value.showScore),
                ),
                child: const PracticeResultAchievementWidget(),
              ),
              Visibility(
                //倒数321
                visible: ref.watch(
                  resultPageController.select((value) => value.showResultCountDown),
                ),
                child: const PracticeResultCountDownWidget(),
              ),
            ],
          ),
        ),
      ),
    );
  } 

这段代码是一个 Flutter 的 Widget 构建方法,用于构建展示评测报告的页面。让我们一步步解释:

  1. listenKeepAlive():这个方法是自定义的,可能是用来监听页面的保活状态的。在 Flutter 中,有一些情况下,页面可能被销毁而不是立即被垃圾回收,以提高性能。但某些情况下,我们可能希望页面一直保持活跃状态,这时就可以使用 AutomaticKeepAliveClientMixin,并在页面中实现 wantKeepAlive 方法。在这里调用 listenKeepAlive 方法可能是为了处理这方面的逻辑。
  2. WillPopScope:这是一个 Widget,用于监听用户尝试通过返回按钮退出页面的事件。在这里,onWillPop 参数指定了一个回调函数 _onWillPop,表示用户点击返回按钮时会执行 _onWillPop 方法。
  3. AiCommonScaffold:这可能是一个自定义的脚手架(Scaffold)Widget,封装了一些通用的页面结构,例如 AppBar、BottomNavigationBar 等。
  4. Listener:是一个通用的手势监听器,可以监听用户的手势操作。在这里,通过 onPointerDown 事件,当用户按下屏幕时执行一段逻辑。具体来说,当用户按下屏幕时,会检查 resultPageController 中的 showResultCountDown 属性,如果为 true,则通过 setShowResultCountDown 方法将其设置为 false
  5. Stack:是一个叠加的 Widget,可以将子 Widget 堆叠在一起。在这里,使用 Stack 将页面分为多个层叠区域。
  6. Column:是一个垂直排列的 Widget,包含两个子 Widget。第一个子 Widget 是一个具有背景颜色的 Container,用于显示页面的标题栏。第二个子 Widget 是一个 Expanded,占据剩余空间,包含一个 PracticeResultScore Widget,用于展示评测的得分。
  7. Visibility:用于控制子 Widget 的可见性。在这里,根据 resultPageController 中的 showScore 属性,决定是否显示 PracticeResultTopBar
  8. Positioned:将子 Widget 定位在 Stack 中的指定位置。在这里,根据页面设计,将一个 GestureDetector 放置在右上角,用于弹出练习反馈对话框。
  9. GestureDetector:是一个手势检测的 Widget,在用户点击时执行相应的操作。在这里,点击时弹出一个练习反馈对话框。
  10. AiImage:是一个自定义的图片 Widget,可能用于展示一个图片资源。
  11. PracticeResultAchievementWidget:一个用于展示评测成就的 Widget,根据 resultPageController 控制其可见性。
  12. PracticeResultCountDownWidget:用于展示倒数计时的 Widget,同样根据 resultPageController 控制其可见性。

总体来说,这个页面包含了评测报告的各个组成部分,通过 resultPageController 控制这些组件的状态和可见性。用户在页面上的交互,例如点击屏幕、返回按钮等,都会触发相应的逻辑。


举报

相关推荐

0 条评论