-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GestureDetector doesn't receive events when it's child is a ListView or a ScrollView. #72996
Comments
@parsa-fs import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
home: Material(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => print('gesture detected'),
child: ListView.builder(
itemBuilder: (context, _) => const Center(
child: FlutterLogo(size: 80),
),
),
),
),
),
);
|
I think this is an old duplicated issue which seems like a bug. You should use Listener because yes. |
Hey @iapicca , |
@parsa-fs |
+1 to a full code sample. Flutter uses a gesture arena instead of something like event bubbling on the web. It can be tough to listen for the same gesture in two different nested widgets. Here is an example of how we do this for taps in the framework. |
I know that here in this code I can use a DraggableScrollableBottomSheet, but If I have a dynamic child in the outer ListView, and if that child is another ListView which I can't pass it my own controller, it fails to handle the height of the bottom sheet. |
flutter doctor -v
|
It's interesting too, that the GestureDetector widget inherits from the Listener widget, but it can't receive the drag gestures, though Listener can. |
Could you achieve what you want by listening to scroll changes? |
Unfortunately no, because I need to know when the user starts dragging and when it ends. |
Check #73039 |
As I understood, there aren't many similarities between these two issues. I want to wrap my ListView inside a GestureDetector, but that issue is the opposite. |
Hey everyone, |
Maybe this can help you Try to compare what you need with the package property panelBuilder |
FLUTTER在点击事件拦截上有很多问题,谁有解决办法吗?比如#62833 应该也是事件拦截问题。 |
https://stackoverflow.com/questions/52910339/flutter-gesturedetector-apparently-doesnt-receive-drag-events-when-it-has-a-li |
I have a similar issue, I would like to achieve a "semantic zoom" effect, I wrapped my scrollView with a GestureDetector, but sometimes it just ignores my pinchzoom, and starts scrolling the scrollview, even if multiple touches are happening. (visible by devtool settings) |
Ok so I went through the implementation of the scrollview, it uses a scrollbale, which has a defined RawGestureDetector with Vertical or Horizontal drag gesture, there is a listener in the scrollable, I added a pointer counter by using the Listener onPointer events, in case the number of pointers > 1 I disable the drag gesture recognition and I cancel any running drags, after this a gesture detector works above a custom customScrollview in my case. You have to simply recreated the customScrolview which should use an edited scrollable. The easiest soulution would be if there would be a single pointer drag gesture, which would not allow scrolling with multiple fingers, and by a simply boolean this behavior could be overwritten. |
can I get your code,appreciate! |
@1232209 |
From the original code sample, this appears to be working as expected, a GestureDetector above a vertical list view will not receive a vertical drag because the ListView claims that gesture. There was a suggestion to listen to scroll notifications - you can listen to the start, update and end of the scrolling with notifications. |
Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. |
Just a note for anyone reading in, 'flutter_map' has also had this problem (see fleaflet/flutter_map#1308). We are using a However, the weirdest part is, not all devices behave the same way. Specifically, iOS doesn't seem to have an issue, whereas every other platform does. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Use case
Basically, when you want to receive the gesture events that happen on a widget, you'd wrap that widget inside a GestureDetector.
That works fine, except when that child widget is a ListView or a SingleChildScrollView. In those scenarios, GestureDetector doesn't receive those events and you need to use a Listener widget, which receives low-level gestures and has pretty basic gesture callbacks. And it is a pain to add thresholding deltas to prevent it from detecting taps instead of drag starts.
Proposal
It would be awesome if flutter had this ability to receive gestures when a ListView or a ScrollView is inside a GestureDetector.
The text was updated successfully, but these errors were encountered: