如何使showModalBottomSheet的背景可按?

3
就像标题所说,当 showModalBottomSheet 出现时,我想在屏幕上按下一些按钮而不关闭 showModalBottomSheet,我已经设置好了。
isDismissible: false,
barrierColor: Colors.transparent,

但是任何按钮都无法按下


我想你做不到。这就是为什么它被称为“模态”的原因。 - Patrick
1个回答

1
你的问题的简短回答是:用一个 GestureDetector 包裹你的底部表单,然后在其中进行一些处理,避免触摸事件到达模态表单。从我所了解的情况来看,ModalBottomSheet 内部使用 BottomSheet 和其代码,实际呈现的方式如下: 这里有一个类似的 SO 答案链接
return AnimatedBuilder(
  animation: widget.route!.animation!,
  child: BottomSheet(
    animationController: widget.route!._animationController,
    onClosing: () {
      if (widget.route!.isCurrent) {
        Navigator.pop(context);
      }
    },

如果你查看onClosing()回调函数,它只是简单地关闭对象,而没有与任何外部回调进行检查,因此我认为在Flutter中使用模态底部表单无法实现这一点,除非将其包装在GestureDetector中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接