Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect scroll position of ListView in Flutter

I'm using ListView widget to show items as a list. In a window three, items viewing must the middle item place in the middle.

So how can I detect position of ListView when scrolling stop?

How to detect ListView Scrolling stopped?

like image 714
majidfathi69 Avatar asked Jan 06 '19 19:01

majidfathi69


People also ask

How do I scroll to a specific position in ListView flutter?

A scroll controller creates a [ScrollPosition] to manage the state-specific to an individual [Scrollable] widget. To use a custom [ScrollPosition], subclass [ScrollController] and override [createScrollPosition]. A [ScrollController] is a [Listenable].

What is scroll offset in flutter?

forward, then scroll offset is the amount the top of the sliver has been scrolled past the top of the viewport. This value is typically used to compute whether this sliver should still protrude into the viewport via SliverGeometry. paintExtent and SliverGeometry.


1 Answers

I used NotificationListener that is a widget that listens for notifications bubbling up the tree. Then use ScrollEndNotification, which indicates that scrolling has stopped.

For scroll position I used _scrollController that type is ScrollController.

NotificationListener(   child: ListView(     controller: _scrollController,     children: ...   ),   onNotification: (t) {     if (t is ScrollEndNotification) {       print(_scrollController.position.pixels);     }   }, ), 
like image 94
majidfathi69 Avatar answered Sep 21 '22 23:09

majidfathi69