The only reasonable solution I can think of is to have a GestureDetector on the transparent container, which will give you the global position of the taps:GestureDetector( onTapUp: (TapUpDetails tapUpDetails) { print("onTapUp global: " + tapUpDetails.globalPosition.toString()); },,然后将Key添加到列表后面的小部件,并使用它来获取小部件矩形左上角的全局位置以及小部件的大小,并使用它们来获取小部件的矩形:And then add a Key to the widget behind the list, and use it to get the global position of the top left corner of the widget's rectangle, as well as the size of the widget, and use those to get the rectangle of the widget:RenderBox renderBox = _key.currentContext.findRenderObject();Offset topLeftCorner = renderBox.localToGlobal(Offset.zero);Size size = renderBox.size;Rect rectangle = topLeftCorner & size;如果背景小部件不移动,则可以使用WidgetsBinding.instance.addPostFrameCallback在下一帧的initState中进行操作(如果在initState中同步进行操作,则渲染对象将为null)并保存Rect -否则,您每次点击都必须重新计算一次.If the background widget does not move, you can do it within initState on the very next frame using WidgetsBinding.instance.addPostFrameCallback (the render object will be null if do it synchronously within initState) and save the Rect - otherwise you will have to recalculate it on every tap.然后最后在透明容器上的每个点击上,您都可以计算出该点击的位置是否在背景小部件的边界内,并调用相应的代码:And then finally on each tap on the transparent container you can calculate whether the tap's position is within the boundaries of the background widget, and invoke the corresponding code:// if tap is within boundaries of the background widgetif (rectangle.contains(tapUpDetails.globalPosition)) { // your code here} 这篇关于Flutter:如何使ListView对指针事件透明(但对非透明内容不透明)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-31 01:43