Layou
Layou

Reputation: 59

flutter GestureDetector ListView

When I have a ListView in GestureDetector and I override onVerticalDragUpdate method, the ListView can't scroll.
How can I both override onVerticalDragUpdate method so that ListView remains scrollable?

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

Upvotes: 1

Views: 2336

Answers (1)

Albert Lardizabal
Albert Lardizabal

Reputation: 6846

If you want to inspect the DragUpdateDetails, you can wrap the ListView inside of a 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'),
            );
          },
        ),
      ),
    );
  }

Upvotes: 1

Related Questions