【问题标题】:Flutter : How to disable drag down to close showModalBottomSheetFlutter:如何禁用向下拖动以关闭 showModalBottomSheet
【发布时间】:2020-07-06 18:05:41
【问题描述】:

我想禁用向下拖动以关闭 showModalBottomSheet

我已经尝试过使用enableDrag:false,

当我使用 enableDrag:false, 时,显示以下错误

下面是我的代码

 modal(BuildContext context) {
    showModalBottomSheet(
        context: context,
        enableDrag:false,
        isDismissible: false,
        backgroundColor: Colors.transparent,
        builder: (context) {
          return Container(
            width: MediaQuery.of(context).size.width,
            child: Stack(
              alignment: Alignment.topCenter,
              children: <Widget>[
                Container(
                  width: MediaQuery.of(context).size.width,
                  padding: EdgeInsets.only(top: 30),
                  child: Stack(
                    alignment: Alignment.topCenter,
                    children: <Widget>[
                      ClipPath(
                        clipper: OvalTopBorderClipper(),
                        child: Container(
                          width: MediaQuery.of(context).size.width,
                          padding: EdgeInsets.only(top: 80),
                          color: Colors.white,
                          height: 440,
                          child: Text("This is a modal bottom sheet !"),
                        ),
                      ),
                    ],
                  ),
                ),
                Positioned(
                  top: 5,
                  child: Container(
                    width: 50.0,
                    height: 53.0,
                    child: Center(
                      child: Text(
                        "K",
                        style: TextStyle(
                            color: AppColors.textColor, fontSize: 20.0),
                      ),
                    ),
                    padding:
                        EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
                    decoration: BoxDecoration(
                        border:
                            Border.all(color: AppColors.textColor, width: 2)),
                  ),
                ),
              ],
            ),
          );
        });
  }

我已经看过这篇文章了

如果需要更多信息,请告诉我。提前致谢。您的努力将不胜感激。

【问题讨论】:

  • 你能跑flutter doctor

标签: flutter dart modal-dialog flutter-showmodalbottomsheet


【解决方案1】:

enableDrag 在showModalBottomSheet 中不可用。我认为它从未在稳定的频道中可用。根据当时链接中的 cmets,它在主频道中可用。但是该链接的第二个答案效果很好

builder: (context) => GestureDetector(
                    onVerticalDragDown: (_) {},
                    child: ...,

here 是 showModalBottomSheet 的文档。您可以随时点击showModalBottomSheet 并对其进行自定义.. 根据文档

BottomSheet,它成为由作为构建器参数传递给 showModalBottomSheet 的函数返回的小部件的父级。

并且BottomSheet 具有enableDrag 参数。

【讨论】:

    【解决方案2】:

    截至 2020-05-06,flutter v1.17.1 enableDrag 可在 showModalBottomSheet 上使用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      • 2019-11-12
      • 2015-05-31
      • 1970-01-01
      • 2022-08-10
      • 2019-11-15
      相关资源
      最近更新 更多