1

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"),
........)
Akif
  • 7,098
  • 7
  • 27
  • 53
Merym
  • 731
  • 7
  • 18

1 Answers1

2

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();
Maz341
  • 2,232
  • 15
  • 20