首页 > 解决方案 > 向下滚动内部可滚动时关闭底部工作表

问题描述

我有 Flutter 的全屏模态底页,SingleChildScrollView里面有它。

正常结果是,无论我向上还是向下滚动,它都会滚动内部可滚动。我可以通过向下拖动可滚动之外的任何内容来关闭模态底部工作表(对我来说,这是一个带有拖动手柄的小容器)。

问题是如果我拉下内部可滚动,我想拉下底页。在做了一些研究之后,我发现我应该使用AlwaysScrollableScrollPhysicsNeverScrollableScrollPhysics但我真的找不到最好的解决方案。

我的想法是允许内部可滚动滚动,直到它的滚动偏移为负。那是行不通的,因为当我停止滚动而不关闭底部工作表时,我需要某种方法使其可滚动。

我可以将内部可滚动包装到GestureDetector并检查滚动增量,但还没有成功。

也许有人遇到过类似的问题并得到了一些例子或算法?

标签: flutter

解决方案


添加modal_bottom_sheet并使用showMaterialModalBottomSheet

showMaterialModalBottomSheet(
                          context: context,
                          builder: (context) {
                            return SingleChildScrollView(
                              child: Column(
                                children: [
                                  Container(
                                    width: MediaQuery.of(context).size.width,
                                    height: MediaQuery.of(context).size.height * 0.8,
                                    color: Colors.green,
                                  ),
                                  Container(
                                    width: MediaQuery.of(context).size.width,
                                    height: MediaQuery.of(context).size.height * 0.8,
                                    color: Colors.red,
                                  ),
                                ],
                              ),
                            );
                          });

推荐阅读