I have 2 Text
widget inside an GestureDetector
. The onTap
callback only notify when I touch on the Text
but not the empty space inside my Container
. How to make this notify like I touch on a button?
+------------------------------------------------+
| Very very very long long ◎ng long text view |
| Short ◎xt ⦿ |
+------------------------------------------------+
Tapped
.My source code:
ListView.separated(
itemCount: _listModel.length,
padding: EdgeInsets.only(left: NOTIFICATION_LEFT_SPACE),
separatorBuilder: (context, index) => Divider(),
itemBuilder: (BuildContext context, int index) => GestureDetector(
child: Container(
child: Hero(
tag: _listModel[index].title,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Very very very long long long long text view'),
SizedBox(height: 10),
Text('Short text')
],
),
),
),
onTap: () {
print('Tapped');
},
),
)
They both provide many common features like onTap , onLongPress etc. The main difference is GestureDetector provides more controls like dragging etc. on the other hand it doesn't include ripple effect tap, which InkWell does.
Long story short, when multiple gestures are detected for the same widget (tree), Flutter will decide which GestureDetector will handle the event based on a combination of factors.
ExpandTapWidget can be wrapped inside/outside GestureDetector: To avoid the conflict of gesture, it is better to apply on the innermost/smallest widget. The expanded area wouldn't exceed the boundary of the Parent Box. You can set debugPaintExpandAreaEnabled = true to display the actual expanded area.
You can use behavior: HitTestBehavior.opaque
property of GestureDetector
widget, that helps to tap on the placeholder inside Container
even if Container
widget doesn't have any child.
GestureDetector(
behavior: HitTestBehavior.opaque,
child: Container(
child: Hero(
tag: 'test',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Very very very long long long long text view'),
SizedBox(height: 10),
Text('Short text')
],
),
),
),
onTap: () {
print('Tapped');
},
),
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