I have a list view of items but I would love to know how I can find its current position inside a listview, does anyone know?
Asked
Active
Viewed 6,380 times
2
-
What do you mean by position? Index is already there by which you can figure out the position. – Dhrumil Shah - dhuma1981 Apr 15 '19 at 05:26
-
I think he needs to know the last element visible on the screen. so he can view count like 5/10 – Saifallak Jun 23 '20 at 13:01
2 Answers
2
Use a ListView.builder
like this:
ListView.builder(
itemCount: items.length,
itemBuilder: (BuildContext context, int index) {
return new Text('The Position is: $index');
}
)
The index represents the position of the item.

JideGuru
- 7,102
- 6
- 26
- 48
1
I believe your question does not fall into this situation:
ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
return new Text('my Index is: $index');
}
)
But rather on how to know where are you currently scrolled:
I would suggest to follow this article
Expanded(
child: NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
// Basically you need something like:
// final _index = scrollOffset (or position) / item height;
},
child: ListView.builder(
itemCount: 30,
itemBuilder: (context, index) {
return ListTile(title: Text("Index : $index"));
},
),
),
),

Durdu
- 4,649
- 2
- 27
- 47