Home > Blockchain >  how to put GestureDetector inside Container alert
how to put GestureDetector inside Container alert

Time:11-29

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);
      },
    );
  }

CodePudding user response:

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",
                    ),
                  )),
            )
          ],
        )),
      )
  • Related