Flutter scroll slowly to the bottom of a dynamic Listview
449
Solution 1
The issue was caused from the animation itself not the duration.
I solved it by increasing the duration and setting
curve: Curves.linear
.
Solution 2
// Declaring the controller and the item size
ScrollController _scrollController;
final itemSize = 100.0;
// Initializing
@override
void initState() {
_scrollController = ScrollController();
_scrollController.addListener(_scrollListener);
super.initState();
}
// Your list widget (must not be nested lists)
ListView.builder(
controller: _scrollController,
itemCount: <Your list length>,
itemExtent: itemSize,
itemBuilder: (context, index) {
return ListTile(<your items>);
},
),
// With the listener and the itemSize, you can calculate which item
// is on screen using the provided callBack. Something like this:
void _scrollListener() {
setState(() {
var index = (_scrollController.offset / itemSize).round() + 1;
});
}
Author by
Yahya
Graduate With CS Degree from College. Proficient in: HTML CSS JQuery PHP VB.Net C# Java for Android Development Swift 4 & 5 for IOS Development Swift UI Flutter
Updated on December 29, 2022Comments
-
Yahya over 1 year
I have a list view that its item may vary each time. I want to make auto scroll for it.
I tried this code
scrollController.animateTo( scrollController.position.maxScrollExtent, duration: Duration(seconds: 10), curve: Curves.easeOut);
It works perfectly for small list view but when the list view items are 100 or more it start moving so fast.
I also tried to make the duration longer when the list view have more items but it mess up
-
Ujjwal Raijada about 3 yearsare you getting the data through api?
-
Yahya about 3 yearsthe data isn't a problem I'm getting the data correctly from local db.
-
Ujjwal Raijada about 3 yearsare you getting all the data at once? Or you are using pagination?
-
Yahya about 3 yearsYes im getting the data at once and filling the listview then I want It to start scrolling.
-
-
Yahya about 3 yearsNo time isn't the problem. I already said that when I set longer time it still works put it moves in a messy way. like it stops then move
-
Tasnuva Tavasum oshin about 3 yearsscrollController.position.maxScrollExtent Change this
-
Yahya about 3 yearsChange it to what ?
-
Tasnuva Tavasum oshin about 3 yearsi have changed my answer have a look
-
Yahya about 3 yearsThe items size aren't static it will change based on the content inside it. Is there any other solution without using the height
-
Tasnuva Tavasum oshin about 3 yearsuse custom scroll
-
Yahya about 3 yearsThis code waits two seconds then it starts scrolling very fast. My problem is with the fast scrolling but its not a time issue
-
Ujjwal Raijada about 3 yearsyou can use
Curves.easeIn
or any other class. There are many options available. -
Ujjwal Raijada about 3 years
-
Yahya about 3 yearsThank you Ujjwal. I solved it by setting the curve to
Curves.linear
. -
Yahya about 3 yearsNo need for that.