Flutter:如何禁用向下拖动以关闭 showModalBottomSheet

Gok*_*oku 2 modal-dialog dart flutter flutter-showmodalbottomsheet

我想禁用向下拖动以关闭 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)),
                  ),
                ),
              ],
            ),
          );
        });
  }
Run Code Online (Sandbox Code Playgroud)

我已经检查过这个帖子了

如果需要更多信息,请告诉我。提前致谢。您的努力将受到赞赏。

Lon*_*olf 6

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

builder: (context) => GestureDetector(
                    onVerticalDragDown: (_) {},
                    child: ...,
Run Code Online (Sandbox Code Playgroud)

是 的文档showModalBottomSheet。您可以随时点击showModalBottomSheet并自定义它..根据文档

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

并且BottomSheetenableDrag参数。