Is there any way to make a GestureDetector override the functionality of all children GestureDetectors?
I have a complex Widget that I would like to be able to easily override all of its behavior at a high level. For example, locking a free user out of functionality.
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.
onTapDown. A pointer that might cause a tap with a primary button has contacted the screen at a particular location. This is called after a short timeout, even if the winning gesture has not yet been selected. If the tap gesture wins, onTapUp will be called, otherwise onTapCancel will be called.
GestureDetector. OnGestureListener notifies users when a particular touch event has occurred. To make it possible for your GestureDetector object to receive events, you override the View or Activity's onTouchEvent() method, and pass along all observed events to the detector instance.
HitTestBehavior() opaque → const HitTestBehavior. Opaque targets can be hit by hit tests, causing them to both receive events within their bounds and prevent targets visually behind them from also receiving events. HitTestBehavior() translucent → const HitTestBehavior.
To temporarily disable all child gesture detectors, use an IgnorePointer
widget:
@override
Widget build(BuildContext context) {
bool ignoreChildGestures = true;
return GestureDetector(
onTap: () {
print('parent tapped');
},
child: IgnorePointer(
ignoring: ignoreChildGestures,
child: GestureDetector(
onTapDown: (details) {
// won't be called when ignoring is set to true
print('child tap down!');
},
),
),
);
}
You can change HitTestBehavior behavior
of GestureDetector
to HitTestBehavior.opaque
GestureDetector(
behavior: HitTestBehavior.opaque,
...
)
By default, it uses HitTestBehavior.deferToChild
.
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