Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollController how can I detect Scroll start, stop and scrolling?

Tags:

flutter

dart

I'm using ScrollController for SingleChildScrollView widget where I want to detect when scroll start, end/stop and still scrolling?

How can I detect, I'm using Listene

scrollController = ScrollController()       ..addListener(() {         scrollOffset = _scrollController.offset;       }); 

Also try with _scrollController.position.activity.velocity but didn't help me.

Also there are

_scrollController.position.didEndScroll(); _scrollController.position.didStartScroll(); 

But how can I use it?

like image 815
Govaadiyo Avatar asked May 10 '19 06:05

Govaadiyo


1 Answers

From this link https://medium.com/@diegoveloper/flutter-lets-know-the-scrollcontroller-and-scrollnotification-652b2685a4ac

Just Wrap your SingleChildScrollView to NotificationListener and update your code like ..

NotificationListener<ScrollNotification>(                 onNotification: (scrollNotification) {                   if (scrollNotification is ScrollStartNotification) {                     _onStartScroll(scrollNotification.metrics);                   } else if (scrollNotification is ScrollUpdateNotification) {                     _onUpdateScroll(scrollNotification.metrics);                   } else if (scrollNotification is ScrollEndNotification) {                     _onEndScroll(scrollNotification.metrics);                   }                 },                 child: SingleChildScrollView(                 /// YOUR OWN CODE HERE                ) ) 

And just declare method like

_onStartScroll(ScrollMetrics metrics) {     print("Scroll Start");   }    _onUpdateScroll(ScrollMetrics metrics) {     print("Scroll Update");   }    _onEndScroll(ScrollMetrics metrics) {     print("Scroll End");   } 

You will be notify by particular method.

like image 105
iPatel Avatar answered Sep 24 '22 14:09

iPatel