Reputation: 891
I have a showDialog called inside FloatingActionButton, I want to dismiss the showDialog when the back button is clicked, but it is returned to the previous page without dismiss
MyCode
FloatingActionButton(
onPressed: () async {
await showDialog(
context: context,
// useRootNavigator: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Dialog"),
........)
Upvotes: 1
Views: 145
Reputation: 2459
Because you are passing the wrong context of the page. I had the same issue today i solved it by doing
FloatingActionButton(
onPressed: () async {
await showDialog(
context: context,
// useRootNavigator: false,
builder: (BuildContext dialogContext) {
return AlertDialog(
title: Text("Dialog"),
........)
and then i popped the dialog with the dialogContext
Navigator.of(dialogContext).pop();
Upvotes: 2