I have an area of my widget that is created with an expanded container like:
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: Colors.blueGrey[200],
child: Text(
startTime,
textAlign: TextAlign.left,
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 16,
fontWeight: FontWeight.normal),
),
),
Expanded(
/* If this gesture detector is instantiated the tap is never found;
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => print("OnTap"),
*/
child:
Container(color: Colors.red[600]),
//),
), // Expanded
], // children
), // Column
If the above code is wrapped with this
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => print("OnTap"),
child: Container(
color: Colors.red[600],
child: // Code above
), // Container
), //GestureDetector
), // Expanded
Then the onTap is only registered in the text widget, but never in the last expanded container.
Is it correct that the detection does not trigger on the Container and needs a widget to fill the space to be detected?
Edit I changed the gesture detection for the expanded container to be:
Expanded(
child: Material(
color: Colors.red[600],
child: InkWell(
onTap: () {print("InkWell");},
), // InkWell
), // Material
), // Expanded
And the tap is still not recognized.
The first snippet of code should work fine, I think your getting an error from another part of your code, can you provide the full code please? And also what you're getting in the console.
This is your code snippet fully working in DartPad: https://dartpad.dev/f76d383475c5c7c35ca4bf59b0a83789