Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why the screen becomes dark when an alert was displaying with flutter?

I don’t know why the screen becomes dark when I try to use the alert on initState() in my flutter application.
This is the code :

  if (element.isCharacteristic42) {
             
         
              Scaffold:
              (showDialog(
                  context: context,
                  builder: (context) {
                    return AlertDialog(
                      title: Text('Be Careful an obstacle was detected'),
                      backgroundColor: Color.fromARGB(45, 231, 148, 54),
                      alignment: Alignment.topCenter,
                    );
                  }));
            }

Thanks in advance for your help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The outer shadow is provided by barrierColor of showDialog. You can make it transparent.

And to show dialog inside initState, use addPostFrameCallback to complete the first frame

  @override
  void initState() {
    super.initState();

    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      showDialog(
        context: context,
        barrierColor: Colors.transparent,

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading