Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have a showModalBottomSheet, and isDismissible is set to true, When I click outside the showModalBottomSheet I want to receive the callback for it.
in showModalBottomSheet I have hide button, and on click of hide button i'm doing
Navigator.pop(context)
to hide the dialog,
Tried
whenComplete()
&
then()
but i get callback for every dismiss even for Hide button click.
How do I do it?
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");
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.