I have two containers in a stack and both containers have GestureDetector.The OnTap for the first container is working fine but it's not working with another container. The first container is the image and the second one is the green background aligned partially over the first container.
new Stack( alignment: Alignment(0.0, 1.44), children: <Widget>[ GestureDetector( onTap: () => _openImage(context), child: Container( width: 340.0, foregroundDecoration: new BoxDecoration( color: Color.fromRGBO(155, 85, 250, 0.55)), height: 240.0, child: FadeInImage.assetNetwork( placeholder: 'assets/dimlight.png', image: post.imageUrl, fit: BoxFit.cover, ), ), ), new GestureDetector( child: new Container( color: Colors.green, child: Row( mainAxisSize: MainAxisSize.max, children: <Widget>[ SizedBox(width: 7.0), CircleAvatar( backgroundImage: new AssetImage("assets/boy.png") radius: 30.0, ), SizedBox( width: 7.0, ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[ new SizedBox( height: 20.0, ), Text( post.user.name, style: TextStyle(fontWeight: FontWeight.bold), ), Text( getTimeString(post.timestamp.toString()), style: TextStyle( color: Colors.grey, fontSize: 10.0), ), ], ), SizedBox( width: 20.0, ), ], ), ), onTap: () => _navigateToDetails(context), ) ], )
Layout Screenshot
They both look the same and almost do the same thing, so what is difference between flutter InkWell vs GestureDetector? Generally speaking, GestureDetector provides more gesture control to detect almost every user interaction including dragging, swiping, pinching, etc.
The stack is a widget in Flutter. It contains a list of widgets and places them on top of each other. And it places their children on top of each other like a stack of books. In other words, stack developers would overlap multiple widgets on one screen. As you can add different images or colors using containers in it.
Try setting the behavior
property of GestureDetector
to HitTestBehavior.translucent
.
Using InkWell
instead of GestureDetector
solved my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With