Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove grey background for flutter alert dialog

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();
                  }
                });
              }
            )
          ],
        )
like image 887
Sharhad Bashar Avatar asked Jun 12 '19 15:06

Sharhad Bashar


2 Answers

An alternative solution that partially solves the problem is using an almost transparent color for the barrier:

showDialog<void>(
      barrierColor: Color(0x01000000),
)
like image 166
IAmJulianAcosta Avatar answered Sep 29 '22 03:09

IAmJulianAcosta


Simple solution with barrierColor property in showDialog method which I set white color with opacity value zero and barrier shadow is vanished

AlertDialog alert = AlertDialog(
    backgroundColor: Colors.transparent,
    elevation: 0,
    content: new Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Loader(),
      ],
    ),
  );
  showDialog(
    barrierColor: Colors.white.withOpacity(0),
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return WillPopScope(
            onWillPop: (){},
          child: alert);
    },
  );
like image 21
Sachin Tanpure Avatar answered Sep 29 '22 03:09

Sachin Tanpure