当在showModalBottomSheet外部单击时,如何控制传递给Navigator.pop()的内容?

问题描述 投票:0回答:1

我启动了一个模态底部工作表,然后使用返回的数据作为将来的数据。

var modalFuture = showModalBottomSheet(
                // ...
              );
              modalFuture.then((data) {
                // Use data
              });

我使用以下方式从模态小部件返回数据:

Navigator.pop(context, data);

当完成与我设置的小部件的模态交互时,这很好用。在模态之外单击时遇到问题。在模态之外单击会导致模态自动关闭(使用Navigator.pop(context)调用?)。我可以结束这种互动,但是我想通过它(Navigator.pop(context, data)调用)将数据发送回去。在showModalBottomSheet模态之外单击时,是否有任何方法可以覆盖隐式弹出窗口?

flutter dart modal-dialog future navigator
1个回答
0
投票
WillPopScope( onWillPop: () async { Navigator.pop(context, data); return true; // return true if needs to be popped }, child: ModelWidget( … ), );

这将确保使用后退按钮自动弹出Navigator.pop时被调用。

© www.soinside.com 2019 - 2024. All rights reserved.