首页 > 解决方案 > Flutter GestureDetector ListView

问题描述

当我有一个ListViewinGestureDetector并且我覆盖onVerticalDragUpdate方法时,ListView不能滚动。
我如何才能同时覆盖onVerticalDragUpdate方法以ListView保持可滚动?

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

标签: flutter

解决方案


如果要检查DragUpdateDetails,可以ListViewNotificationListener.

  @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'),
            );
          },
        ),
      ),
    );
  }

推荐阅读