Flutter:如何禁用向下拖动以关闭showModalBottomSheet [英] Flutter : How to disable drag down to close showModalBottomSheet

查看:370
本文介绍了Flutter:如何禁用向下拖动以关闭showModalBottomSheet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to disable drag down to close the 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)),
                  ),
                ),
              ],
            ),
          );
        });
  }

我已经检查过此帖子

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

If need more information please do let me know. Thanks in advance. Your efforts will be appreciated.

推荐答案

enableDrag showModalBottomSheet 中不可用.我认为该频道无法在稳定频道中提供.根据当时链接的评论,该链接可在主频道"中使用.但是该链接的第二个答案效果很好

enableDrag is not available in showModalBottomSheet. I don't think it was ever available in stable channel. According to comments from the link at that time it was available in Master channel. But second answer from that link works well

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

此处 showModalBottomSheet 的文档.您始终可以点击 showModalBottomSheet 并对其进行自定义..根据doc

here is documentation to showModalBottomSheet . You can always tap into the showModalBottomSheet and customise it.. According to doc

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

BottomSheet, which becomes the parent of the widget returned by the function passed as the builder argument to showModalBottomSheet.

BottomSheet 具有 enableDrag 范围.

这篇关于Flutter:如何禁用向下拖动以关闭showModalBottomSheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆