gpt4 book ai didi

flutter GestureDetector ListView

转载 作者:IT王子 更新时间:2023-10-29 07:04:45 35 4
gpt4 key购买 nike

当我在 GestureDetector 中有一个 ListView 并且我覆盖了 onVerticalDragUpdate 方法时,ListView 无法滚动.
我如何重写 onVerticalDragUpdate 方法,使 ListView 保持可滚动?

new GestureDetector(
onVerticalDragUpdate: (details) => print("a"),
child: new ListView(
children: <Widget>[
new Text("a"),
new Text("a"),
new Text("a"),
],
),
)

最佳答案

如果您想检查 DragUpdateDetails,可以将 ListView 包装在 NotificationListener 中。

  @override
Widget build(BuildContext context) {
return Scaffold(
body: NotificationListener(
onNotification: (notification) {
if (notification is ScrollUpdateNotification) {
print('${notification.dragDetails}');
}
},
child: ListView.builder(
itemCount: 20,
itemBuilder: (context, index) {
return ListTile(
title: Text('Index = $index'),
);
},
),
),
);
}

关于 flutter GestureDetector ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54306547/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com