最佳答案
我正在通过 showModalBottomSheet<Null>()
显示一个 BottomSheet,并在几个具有 GestureDetector 的小部件中显示它。
I would like to see the BottomSheet closed not only by touching outside it but also after an onTap event of a GestureDetector inside. However, it seems the GestureDetector is not forwarding the touch event.
所以我想知道,是否有一种方法可以通过编程触发 ModalBottomsheet 的关闭,或者告诉 GestureDetector 转发触摸事件?
更新(2018-04-12) :
下面是一个代码片段,以便更好地理解。问题在于,当点击“ Item1”或“ Item2”时,ModalBottomsheet 没有关闭。
showModalBottomSheet<Null>(context: context, builder: (BuildContext context)
{
return new SingleChildScrollView(child:
new Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
new GestureDetector(onTap: () { doSomething(); }, child:
new Text("Item 1")
),
new GestureDetector(onTap: () { doSomething(); }, child:
new Text("Item 2")
),
]),
);
});