问题
Am I missing something? The documentation says that events bubble up from the innermost child to the ancestors, but below code will not print "dragged" to the console. It does print "tapped" though. Applying NeverScrollablePhyiscs to the ListView does work, but i want to listen on the event on both levels. Applying HitTestBehavior.translucent to the GestureDetector doesn't change anything.
import "package:flutter/material.dart";
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: GestureDetector(
onVerticalDragUpdate: (DragUpdateDetails details) {
print("dragged");
},
onTap: () {
print("tapped");
},
child: ListView.builder(
itemBuilder: (context, index) {
return Container(
padding: EdgeInsets.all(20.0),
child: Text(
"The GestureDetector above me does not react to drag events. Maybe my parent is at fault?"
)
);
},
)
)
);
}
}
回答1:
You can listen for raw pointer events using Listener
return Scaffold(
body: Listener(onPointerMove: (opm) {
print("onPointerMove .. ${opm.position}");
}, child: ListView.builder(
itemBuilder: (context, index) {
return Container(
padding: EdgeInsets.all(20.0),
child: Text(
"The GestureDetector above me does not react to drag events. Maybe my parent is at fault?"));
},
)));
来源:https://stackoverflow.com/questions/52910339/flutter-gesturedetector-apparently-doesnt-receive-drag-events-when-it-has-a-li