【问题标题】:Flutter showModalBottomSheet where the sheet is not dismissible? [closed]Flutter showModalBottomSheet 工作表不可关闭的地方? [关闭]
【发布时间】:2018-06-21 18:36:13
【问题描述】:

我想使用模态底页进行数据输入。我不希望用户只需触摸工作表外即可将其关闭。本文介绍了如何在 Android 原生中做到这一点。

https://medium.com/@betakuang/make-your-bottomsheetdialog-noncancelable-e50a070cdf07

如何使用颤振小部件做到这一点?

【问题讨论】:

    标签: material-design flutter


    【解决方案1】:

    这里

    • 设置 enableDrag false 禁用底部工作表的拖动

    • 设置 isDismissable false 在外部触摸取消时禁用

    • onWillPop 上返回空白会覆盖返回按钮,因此用户无法使用返回按钮返回

       showModalBottomSheet(
         enableDrag: false,
         isDismissible: false,
         context: context,
         builder: (context) {
           return WillPopScope(
            onWillPop: () {},
            child: Container());
         });
      

    【讨论】:

    • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
    • @MarkRotteveel 感谢您的建议。我已经编辑了带有解释的答案。
    • 您需要在 onWillPop 范围内返回 false 以禁用后退按钮。 onWillPop: () async { return false; },
    【解决方案2】:

    模态BottomSheet替代persistent BottomSheet

    您需要做的唯一更改是将showModalBottomSheet 更改为showBottomSheet

    持久 BottomSheet 仍然可以被例如按下返回按钮在 Android 上。这是 nice 行为,因为它是 Material 行为。

    【讨论】:

    • 啊,我不认为“持久”是可以解雇的。我会看的。谢谢。
    • @dakamojo 如果对您有帮助,您可以点赞或接受,这样您的问题就会被视为“已回答”。
    【解决方案3】:

    这种做法对我有用!!

    showModalBottomSheet(
        isDismissible: false, // <--- this line
        clipBehavior: ,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(25.0), topRight: Radius.circular(25.0)),
        ),
        context: context,
        builder: (builder) {
          return Container(
            child: Column(children: <Widget>[
             SizedBox(height: 250,)
            ]),
          );
    
       });
    

    【讨论】:

      猜你喜欢
      • 2020-09-05
      • 2021-02-09
      • 2020-07-06
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 2014-05-04
      • 2016-04-26
      相关资源
      最近更新 更多