颤抖的GestureDetector ListView

时间:2019-01-22 10:46:48

标签: flutter

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

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

1 个答案:

答案 0 :(得分:0)

如果要检查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'),
            );
          },
        ),
      ),
    );
  }