Using a GestureDetector
is not the correct way, here is a way of triggering a method when you stop dragging your scroll view:
class MyWidget extends StatelessWidget {
_onEndScroll(ScrollMetrics metrics) {
print('Stopped Dragging');
}
@override
Widget build(BuildContext context) {
return NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
if (scrollNotification is ScrollEndNotification) {
_onEndScroll(scrollNotification.metrics);
}
return false;
},
child: SingleChildScrollView(
child: Column(children: <Widget>[
...List<Widget>.generate(
100,
(index) => ListTile(title: Text(index.toString())),
)
])),
);
}
}
Simply wrap your scroll view inside a NotificationListener
widget then you will be able to get any notification from your scroll view and you only need to manage your action depending on the notification's type. (I return false
at the end of onNotification
to keep listening to upcoming notification.)
Test the full code on DartPad