Remove grey background for flutter alert dialog

Issue

I have a CupertinoAlertDialog and AlertDialog in my Flutter app. every time the dialog pops up, everything behind it becomes darker. I would like to remove the background. how do I do that?

CupertinoDialogAction(
        child: Text('Delete',
                style: TextStyle(color: Colors.red),
              ),
              onPressed: () async {
                await CommentActivity.delete(postData[index]['id'])
                  .then((response) {
                  if (response) {
                    setState(() {
                      postData.removeAt(index);
                      createPageActivity();
                      renderPageActivity();
                    });
                    Navigator.of(context).pop();
                  }
                });
              }
            )
          ],
        )

Solution

Just launch the dialog with de navigator instead of using the showDialog() and use a PageRouteBuilder

Navigator.of(context).push(
                  PageRouteBuilder(
                      pageBuilder: (context, _, __) => AlertDialog(),
                      opaque: false),
);

Answered By – Sergio Bernal

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *