【问题标题】:How to prevent bottom sheet dismiss flutter如何防止底片消失颤动
【发布时间】:2020-07-16 13:59:25
【问题描述】:

我想防止在向下滑动时关闭bottom sheet, 我想使用Scaffold.of(context).showBottomSheet<void>((BuildContext context) => ...) 而不是showModalBottomSheet 因为我需要脚手架信息,showBottomSheet 有什么解决方案吗?我该怎么做?

【问题讨论】:

标签: flutter bottom-sheet


【解决方案1】:

GestureDetector 包裹小部件并禁用拖动:

Scaffold.of(context).showBottomSheet(
  (context) => GestureDetector(
    child: YourWidget(),
    onVerticalDragStart: (_) {},
  ),
)

【讨论】:

  • 谢谢,但是我想用Scaffold.of(context).showBottomSheet<void>((BuildContext context) => ...)而不是showModalBottomSheet,因为我需要脚手架信息,showBottomSheet有什么解决办法吗?
【解决方案2】:

即使@Sami 的回答工作正常,它也不是很优雅,因为它似乎是一种解决方法。

对于这种情况,您应该使用AbsorbPointer 而不是只使用空手势。

简单地说(粘贴文档):

在命中测试期间吸收指针的小部件。

在你的情况下,你会这样使用:

Scaffold.of(context).showBottomSheet(
  (context) => AbsorbPointer(child: Container()),
)

【讨论】:

    【解决方案3】:

    如果您使用showModalBottomSheet,请使用enableDrag 属性。

    showModalBottomSheet<bool>(
            context: context,
            enableDrag: false,
            ...
            builder: (BuildContext bc) {
               return ..your widgets...
            }
    );
    

    【讨论】:

      【解决方案4】:
      showModalBottomSheet(
          isDismissible: false,
      )
      

      【讨论】:

      • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
      • 谢谢,但是我想用Scaffold.of(context).showBottomSheet&lt;void&gt;((BuildContext context) =&gt; ...)而不是showModalBottomSheet,因为我需要脚手架信息,showBottomSheet有什么解决办法吗?
      猜你喜欢
      • 2017-03-20
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多