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

how to put GestureDetector inside Container alert

I wanna put GestureDetector with container alert but it show error. anyone know how to make this code works? Here the code below which i try to put GestureDetector for the alert container.

Without GestureDetector it works fine but i wanna make whole screen touch able to return to other page.

 showPopup(BuildContext context) {
    // set up the buttons
    // ignore: deprecated_member_use

    // set up the AlertDialog
    GestureDetector(
       Container alert = Container(
        child: Stack(
      children:  <Widget>[
        if (controllers!.isNotEmpty)
          CarouselSlide2(
            controllers: controllers!,
          ),


        Padding(
          padding: const EdgeInsets.only(top:688.0,left: 90),
          child: GestureDetector(
            onTap: () async {
              isPop = false;
              Navigator.pop(context);

              _checkTimer();
            },
            // child: Icon(Icons.arrow_back,color: Colors.white,size: 100,),
            child: DefaultTextStyle(
              style: TextStyle(color: Colors.white,fontSize: 30),
              child:   Text("Tap to return",),
                 )




          ),
        )
      ],
    )));
    // show the dialog
    showDialog(
      barrierDismissible: true,
      context: context,
      builder: (BuildContext context) {
        return WillPopScope(
            onWillPop: () async {
              const shouldPop = true;
              isPop = false;
              Navigator.pop(context);

              _checkTimer();
              return shouldPop;
            },
            child: alert);
      },
    );
  }

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 :

You are using widget in a wrong way, try this:

Widget alert = GestureDetector(
        onTap: () {
          print("tap");
        },
        child: Container(
            child: Stack(
          children: <Widget>[
            if (controllers!.isNotEmpty)
              CarouselSlide2(
                controllers: controllers!,
              ),
            Padding(
              padding: const EdgeInsets.only(top: 688.0, left: 90),
              child: GestureDetector(
                  onTap: () async {
                    isPop = false;
                    Navigator.pop(context);

                    _checkTimer();
                  },
                  // child: Icon(Icons.arrow_back,color: Colors.white,size: 100,),
                  child: DefaultTextStyle(
                    style: TextStyle(color: Colors.white, fontSize: 30),
                    child: Text(
                      "Tap to return",
                    ),
                  )),
            )
          ],
        )),
      )
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