【发布时间】:2021-06-10 22:31:35
【问题描述】:
我使用的是ListWheelScrollView,更具体的是clickable。
(clickable_list_wheel_view)
我试图在我的itemWidget 中添加一个button,但我无法单击它。这是我的list:
return ClickableListWheelScrollView(
scrollController: _scrollController,
itemHeight: _itemHeight,
itemCount: months.length,
scrollOnTap: true,
onItemTapCallback: (index) {
print(index)
},
child: ListWheelScrollView.useDelegate(
controller: _scrollController,
itemExtent: _itemHeight,
physics: FixedExtentScrollPhysics(),
diameterRatio: 3,
squeeze: 0.95,
onSelectedItemChanged: (index) {
// print(index);
},
childDelegate: ListWheelChildBuilderDelegate(
builder: (context, index) => MonthCardWidget(
month: months[index],
),
childCount: months.length,
),
),
);
在我的MonthCardWidget 里面我有这个简单的button:
Container(
height: 45,
width: 45,
color: Colors.transparent,
child: IconButton(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
onPressed: () {
print('flip');
},
icon: SvgPicture.asset('assets/images/flip.svg',
height: 20, width: 20),
),
),
一切都显示得很好,但我的button 从未调用过onPressed。我猜GestureDetector 覆盖了按钮?有什么解决方法吗?我在这方面找不到任何东西。
GestureDetector 只是在listView 之上:
@override
Widget build(BuildContext context) {
if (_listHeight == .0) {
return MeasureSize(
child: Container(
child: widget.child,
),
onChange: (value) {
setState(() {
_listHeight = value.height;
});
},
);
}
return GestureDetector(
onTap: _onTap,
onTapUp: (tapUpDetails) {
_tapUpDetails = tapUpDetails?.localPosition;
},
child: widget.child,
);
}
【问题讨论】:
-
您在描述中提到了 GestureDetector,但它不在您共享的代码中。
-
@JoãoSoares 我链接了
clickableListWheelView。基本上整个list都包裹在GestureDetector中。 -
但是我们看不到这一点,因为您还没有共享那部分代码。您在 GestureDetector 中设置的选项等。如果您想获得帮助,请分享可能影响您问题的代码。
-
@JoãoSoares 更新了我的问题,这有帮助吗?就像我说的,那是来自我链接的包。我在那里没有改变任何东西。您可以查看链接,也许这会使事情更清楚
标签: flutter listview dart widget gesturedetector