[英]How to get the onDismiss callback of showModalBottomSheet in flutter?
I have a showModalBottomSheet, and isDismissible is set to true, When I click outside the showModalBottomSheet I want to receive the callback for it.我有一个 showModalBottomSheet,并且 isDismissible 设置为 true,当我在 showModalBottomSheet 外部单击时,我想接收它的回调。
in showModalBottomSheet I have hide button, and on click of hide button i'm doing Navigator.pop(context)
to hide the dialog,在 showModalBottomSheet 我有隐藏按钮,点击隐藏按钮我正在做
Navigator.pop(context)
来隐藏对话框,
Tried whenComplete()
& then()
but i get callback for every dismiss even for Hide button click.尝试过
whenComplete()
& then()
但即使点击隐藏按钮,我也会在每次关闭时收到回调。
How do I do it?我该怎么做?
Uday,乌代,
You can pass parameter when popping the route to see how modal sheet was closed:您可以在弹出路由时传递参数以查看模态表是如何关闭的:
showModalBottomSheet<bool>(
context: context,
isDismissible: true,
builder: (BuildContext context) {
return Center(
child: RaisedButton(
child: const Text("hide"),
onPressed: () => Navigator.of(context).pop(true), // pass true indicating that it was hidden via button
),
);
},
).then(
(isManuallyHidden) {
if (isManuallyHidden ?? false) {
print("hidden via button");
} else {
print("dismissed");
}
},
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.